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");
}
4 Answers
Reset to default 2I 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
版权声明:本文标题:javascript - Open link in a window using script (Google Sheet) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743966063a2569908.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论