运行 Google Script 网络应用程序后关闭窗口? [英] Closing window after running a Google Script web app?

查看:24
本文介绍了运行 Google Script 网络应用程序后关闭窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了一个小型网络应用程序,当用户单击电子表格中的链接时会打开该应用程序.该链接会将他们带到 Web 应用程序,该应用程序会对电子表格进行更改.我希望浏览器窗口在代码运行完成后自动关闭.

I made a small web app that opens when the user clicks a link in a spreadsheet. The link will take them to web app, which makes changes to a spreadsheet. I want the browser window to close automatically once the code is finished running.

function doGet(e){
  // code make changes to spreadsheet

 // here I want browser window to close

  return HtmlService.createHtmlOutput(uniqueid + " is marked complete");
}; 

感谢帮助

推荐答案

需要区分浏览器标签侧边栏中的Web应用程序或Google 文档(工作表、表单、文档)内的对话框.

A distinction needs to be made between a Web App in a browser tab, and a sidebar or dialog box inside of a Google document (Sheet, Form, Doc).

问题是关于浏览器选项卡中的 Web 应用程序.如果要关闭侧边栏或对话框,只需使用:

The question is about a Web App in a browser tab. If you want to close a sidebar or dialog box, then just use:

google.script.host.close()

但是这个问题是针对 Web 应用程序的.您可以尝试在 HTML 中放置一个脚本标记,并使用在窗口打开时自动运行的代码.

But this question is for a Web App. You can try putting a script tag in the HTML with code that runs automatically when the window is opened.

<script>
  window.top.close();
</script>

如果你想延迟:

<script>
  setTimeout(function(){ window.top.close(); }, 3000);
</script>

您可以尝试使用 window.onload.

<script>
  window.onload=function(){
    console.log("This onload did run");
    setTimeout(function(){ window.top.close(); }, 3000);
  };
</script>

如果您不在乎用户是否看到任何内容,您可以运行 Apps Script Content Service.

If you don't care whether the user sees anything or not, you could just run Apps Script Content Service.

这篇关于运行 Google Script 网络应用程序后关闭窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆