当我在 Google 应用程序脚本中运行 GET 请求时,如何在浏览器选项卡打开后自动关闭它

问题描述

我通过单击指向 Web 应用程序 URL 的链接调用带有 GET 请求的 Google Apps 脚本 Web 应用程序,以启动一个函数

浏览器会自动打开一个带有返回响应的标签

如何立即或在显示消息几秒钟后自动关闭该选项卡。

我环顾四周,看到很多建议添加 <script> 标签,但似乎不起作用。我哪里出错了?

Code.gs

    function doGet(e) {
var pram = e.parameter.param;
    
// Run some code based off of the parameter

        return HtmlService.createHtmlOutputFromFile('confirmation'); 
    }

HTML 文件

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
    <script>
function start(){
    setTimeout(function(){ window.top.close(); },3000);
    }
    </script>
  </head>
  <body onload="start()">
<h2 style="text-align: center;">Your function is being Initiated<br>Please Wait...</h2>
  </body>
</html>

解决方法

简而言之,这是无法做到的。请参阅@TheMaster 的评论。