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

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

问题描述

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

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

感谢您的帮助

Thanks for help

推荐答案

您无法从应用程序脚本代码中关闭窗口。 Apps脚本正在Google服务器上运行,JavaScript在此时无法访问浏览器。您可以将JavaScript放入HTML中,该HTML将在客户端运行(在用户浏览器中,在他们的计算机上),但我无法获得任何东西来使窗口关闭。

You can't get the window to close from Apps Script code. Apps Script is running on Google's server, and JavaScript doesn't have access to the browser at that point. You can put JavaScript inside of the HTML, which will run on the client side, (in the users browser, on their computer), but I couldn't get anything to work to make the window close.

我尝试在HTML中打开脚本标记,并在打开窗口时自动运行代码。

I tried putting a script tag in the HTML with code that runs automatically when the window is opened.

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

我试着拖延时间;那是行不通的。

I tried putting in a delay; that didn't work.

<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>

我无法自动关闭窗口。我也无法使用按钮关闭窗口。

I couldn't get anything to automatically close the window. I also couldn't get a function run from a button to close the window either.

如果你不关心用户是否看到任何东西,你可以运行Apps脚本内容服务。

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

您可以使用带HTML的对话框来显示内容,并且您可以 自动关闭对话框。它不会在另一个浏览器选项卡中打开,但可以自动关闭。

You could use a dialog box with HTML for content, and you can get the dialog box to close automatically. It won't open in another browser tab, but you can make it close automatically.

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

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