最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Open link in a window using script (Google Sheet) - Stack Overflow

programmeradmin1浏览0评论

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

发布评论

评论列表(0)

  1. 暂无评论