从应用程序脚本加载项菜单中打开一个新的 window

Open a new window from the apps script add-on menu

我有一个插件,我需要重定向到外部 URL 而不是在单击菜单时使用对话框或边栏加载。

我有侧边栏代码

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>

在您的 Website.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>

这对我来说很好

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