【问题标题】:Open a Google Doc when the user clicks a button用户单击按钮时打开 Google Doc
【发布时间】:2016-12-03 11:59:26
【问题描述】:

我创建了一个 html 输出,为用户提供了一个按钮,点击时我想按 ID 打开一个 Google 文档。 ID 当前是我的 google 脚本中的一个变量,因此我有 onclick 在我的 .gs 文件中运行一个函数。但是我不确定打开文档的方法,或者我如何将 id 传递给我的 HTML 并直接从我的 onclick 打开文档。

HTML

<input id=nxtBtn type="button" value="Next" onClick="google.script.run.openDoc()";/>

gs

function openDoc(id){
    Logger.log("openDoc: " +id)
    // open google doc script here......???
} 

【问题讨论】:

    标签: javascript html google-apps-script


    【解决方案1】:

    您需要在脚本的 HTML 部分打开链接。

    HTML

    <input id=nxtBtn type="button" value="Next" onClick="google.script.run.withSuccessHandler(openLink).getDocUrl()";/>
    

    您的 HTML 脚本

    function openLink(url) {
      window.open(url, "_blank");
    }
    

    gs

    function getDocUrl() {
      var id = "You somehow get your id";
      return DriveApp.getFileById(id).getUrl();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-01
      • 2016-03-12
      相关资源
      最近更新 更多