3

I'm trying to create a function inside Google Script Editor that would open a link and keep getting ERROR messages

function myfunction() { browser.window.open("link");
}

Alex Kors
  • 182
  • 1
  • 4
  • 10

4 Answers4

1

I was looking for the same thing and found the solution below.
In this case it opens the link in the cell, that is selected when you press the button.
You could however just change the "selection" part and insert a url directly.

function openTab() {
var selection = SpreadsheetApp.getActiveSheet().getActiveCell().getValue();

var html = "<script>window.open('" + selection + "');google.script.host.close();</script>";

var userInterface = HtmlService.createHtmlOutput(html);

SpreadsheetApp.getUi().showModalDialog(userInterface, 'Open Tab');
}

They seem to have tightened security however, when I try this in Chrome, the new window is blocked by the built-in pop-up blocker. And Firefox doesn't even seem to try and open the link.
The Firefox issue might however be because I haven't logged in on my google account in Firefox and it seems to require authorization to run any scripts attached to sheets.

Ref: https://www.youtube.com/watch?v=2y7Y5hwmPc4

Bramako
  • 13
  • 4
1
function openTab() {
var selection = SpreadsheetApp.getActiveSheet().getActiveCell().getValue();

var html = "<script>window.open('" + selection + "');google.script.host.close();</script>";

var userInterface = HtmlService.createHtmlOutput(html);

SpreadsheetApp.getUi().showModalDialog(userInterface, 'Open Tab');
}
Tu.Ma.
  • 1,325
  • 10
  • 27
  • Welcome! Code is helpful, but some context and explanation will make it even better. I'd suggest adding a little text, along with proper code formatting to really make this answer the best it can be. – Mattie Dec 07 '18 at 15:27
0

Try just:

window.open(url,'_blank');
Pabs123
  • 3,385
  • 13
  • 29
0

Google Apps Script in spreadsheets is executed on Google's servers. So it can not tell your browser to open a new tab or window without a user explicitly doing some action (in other words, clicking the url).

StasiekK
  • 66
  • 1
  • 3