Javascript 从应用程序脚本附加菜单打开一个新窗口
我有一个附加组件,我需要重定向到外部URL,而不是在单击菜单时使用对话框或侧边栏加载 我有侧边栏代码Javascript 从应用程序脚本附加菜单打开一个新窗口,javascript,google-apps-script,google-spreadsheet-api,Javascript,Google Apps Script,Google Spreadsheet Api,我有一个附加组件,我需要重定向到外部URL,而不是在单击菜单时使用对话框或侧边栏加载 我有侧边栏代码 function showContactDialog() { var html = HtmlService.createTemplateFromFile('Website').evaluate().setSandboxMode(HtmlService.SandboxMode.IFRAME).setWidth(480).setHeight(380); SpreadsheetApp.
function showContactDialog() {
var html = HtmlService.createTemplateFromFile('Website').evaluate().setSandboxMode(HtmlService.SandboxMode.IFRAME).setWidth(480).setHeight(380);
SpreadsheetApp.getUi().showModalDialog(html, 'Website');
}
在HTML中,您可以打开一个新选项卡(如果您的浏览器支持此功能),但不能重定向页面 在HTML中,您可以执行以下操作:
<script>
function openPage() {
window.open('https://google.com', '_blank');
}
window.onload = openPage;
</script>
函数openPage(){
打开窗户https://google.com","空白",;
}
window.onload=openPage;
在您的网站.html
中放置此代码
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<script type="text/javascript">
function opentab(){
window.open(LINK_YOU_WANT_TO_OPEN, '_blank');
}
</script>
</head>
<body onload="opentab()">
</body>
</html>
函数opentab(){
window.open(链接你想要打开,''u blank');
}
这对我来说很好
function open_new_doc()
{
var html = '<script>google.script.host.close();'+
'window.location.href = "'+open_url+'"</script>';
var html_open = HtmlService.createHtmlOutput(html).setSandboxMode(HtmlService.SandboxMode.IFRAME);
DocumentApp.getUi().showModalDialog(html_open, 'Opening New Window...');
}
函数open\u new\u doc()
{
var html='google.script.host.close();'+
'window.location.href=“”+打开url+”;
var html_open=HtmlService.createHtmlOutput(html).setSandboxMode(HtmlService.SandboxMode.IFRAME);
DocumentApp.getUi().showModalDialog(html_open,“打开新窗口…”);
}