Google Apps Script to open a URL

后端 未结 5 500
梦谈多话
梦谈多话 2020-11-22 10:39

Is there a way to write a google apps script so when ran, a second browser window opens to www.google.com (or another site of my choice)?

I am trying to come up with

5条回答
  •  难免孤独
    2020-11-22 11:20

    Google Apps Script will not open automatically web pages, but it could be used to display a message with links, buttons that the user could click on them to open the desired web pages or even to use the Window object and methods like addEventListener() to open URLs.

    It's worth to note that UiApp is now deprecated. From Class UiApp - Google Apps Script - Google Developers

    Deprecated. The UI service was deprecated on December 11, 2014. To create user interfaces, use the HTML service instead.

    The example in the HTML Service linked page is pretty simple,

    Code.gs

    // Use this code for Google Docs, Forms, or new Sheets.
    function onOpen() {
      SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
          .createMenu('Dialog')
          .addItem('Open', 'openDialog')
          .addToUi();
    }
    
    function openDialog() {
      var html = HtmlService.createHtmlOutputFromFile('index')
          .setSandboxMode(HtmlService.SandboxMode.IFRAME);
      SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
          .showModalDialog(html, 'Dialog title');
    }
    

    A customized version of index.html to show two hyperlinks

    Stack Overflow
    
    Meta Stack Overflow

提交回复
热议问题