-1

I couldn't find how to open the hyperlink in same tab by button with google script in google sheet. Does anybody know how to fix my problem?

Rubén
  • 34,714
  • 9
  • 70
  • 166
Ditoo
  • 7
  • 2

1 Answers1

1

Opening a link from a url in the sheet with a button on a dialog

function gotoalinkwithadialogbutton() {
  var ss=SpreadsheetApp.getActive();
  var sh=ss.getActiveSheet();
  var rg=sh.getActiveCell();
  var href=rg.getValue();
  var html='<input type="button" value="Link" onClick="gotoLink();" />';
  html+='<script>function gotoLink(){google.script.run.withSuccessHandler(function(url){window.open(url);}).getLinkValue()}console.log("Here");</script>';
  var userInterface=HtmlService.createHtmlOutput(html);
  SpreadsheetApp.getUi().showModelessDialog(userInterface, "Go To Link")
}

function getLinkValue() {
  return SpreadsheetApp.getActiveRange().getValue();
}

The dialog could be a sidebar I believe.

Cooper
  • 59,616
  • 6
  • 23
  • 54
  • 1
    I was just trying to find a way to do it with a button to answer the OPs question. Personally, I’d probably be happy to click on the link produced by the cell. But that wasn’t the question. – Cooper May 20 '19 at 14:28
  • Ah yes. Missed the button part. – TheMaster May 20 '19 at 14:38