admin管理员组

文章数量:1357393

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");
}

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");
}

Share Improve this question asked Mar 6, 2017 at 17:55 Alex KorsAlex Kors 2021 gold badge5 silver badges10 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 2

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./watch?v=2y7Y5hwmPc4

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');
}

Try just:

window.open(url,'_blank');

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).

本文标签: javascriptOpen link in a window using script (Google Sheet)Stack Overflow