首页 > 解决方案 > 如何通过代码打开多个网址,我们有一个代码,但它只有一个网址

问题描述

我们有以下脚本,我们在谷歌脚本编辑器中运行它,它工作正常,但它只打开一个 url,如果我们想打开多个 url,我们该怎么做

功能是

function myFunction() {
  var js = " \
    <script> \
      window.open('https://stackoverflow.com/', '_blank', 'width=800, height=600'); \
      google.script.host.close(); \
    </script> \
  ";
  var html = HtmlService.createHtmlOutput(js)
    .setHeight(10)
    .setWidth(100);
  SpreadsheetApp.getUi().showModalDialog(html, 'Now loading.'); 
}

标签: google-apps-script

解决方案


有了window.open您可以打开任意数量的窗口

在两个不同的窗口中打开两个 url 的示例:

function myFunction() {
  var js = " \
    <script> \
      window.open('https://stackoverflow.com/', '_blank', 'width=800, height=600'); \
     window.open('https://www.wikipedia.org/', '_blank', 'width=800, height=600'); \
      google.script.host.close(); \
    </script> \
  ";
  var html = HtmlService.createHtmlOutput(js)
    .setHeight(10)
    .setWidth(100);
  SpreadsheetApp.getUi().showModalDialog(html, 'Now loading.'); 
}

推荐阅读