【问题标题】:Open link in a window using script (Google Sheet)使用脚本在窗口中打开链接(Google Sheet)
【发布时间】:2017-03-06 17:55:07
【问题描述】:

我正在尝试在 Google 脚本编辑器中创建一个可以打开链接并不断收到错误消息的函数

function myfunction() { browser.window.open("link");
}

【问题讨论】:

    标签: javascript editor


    【解决方案1】:

    我一直在寻找同样的东西,并在下面找到了解决方案。
    在这种情况下,它会打开单元格中的链接,该链接在您按下按钮时被选中。
    但是,您可以只更改“选择”部分并直接插入一个 url。

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

    他们似乎加强了安全性,但是,当我在 Chrome 中尝试此操作时,新窗口被内置的弹出窗口阻止程序阻止。 Firefox 甚至似乎都没有尝试打开该链接。
    然而,Firefox 问题可能是因为我没有在 Firefox 中登录我的 google 帐户,并且似乎需要授权才能运行附加到工作表的任何脚本。

    参考:https://www.youtube.com/watch?v=2y7Y5hwmPc4

    【讨论】:

      【解决方案2】:
      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');
      }
      

      【讨论】:

      • 欢迎您!代码很有帮助,但一些上下文和解释会使它变得更好。我建议添加一些文本以及适当的代码格式,以真正使这个答案成为最好的。
      【解决方案3】:

      试试吧:

      window.open(url,'_blank');
      

      【讨论】:

        【解决方案4】:

        电子表格中的 Google Apps 脚本在 Google 的服务器上执行。因此,它无法告诉您的浏览器在没有用户明确执行某些操作(换句话说,单击 url)的情况下打开新选项卡或窗口。

        【讨论】:

        • 我正在使用“按钮”来运行该功能,因此用户确实会明确点击链接
        猜你喜欢
        • 1970-01-01
        • 2021-02-04
        • 1970-01-01
        • 2012-04-11
        • 2013-12-04
        • 1970-01-01
        • 1970-01-01
        • 2015-02-09
        • 2017-11-14
        相关资源
        最近更新 更多