Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
320 views
in Technique[技术] by (71.8m points)

javascript - How to automatically close a browser tab after it opens when I run a GET request in a Google apps script

I'm calling a Google Apps Script webapp with a GET request by clicking a link to the webapp's Url, to initiate a function.

The browser automatically opens a tab with the return response.

How can I automatically close that tab immediately or after a few seconds of displaying a message.

I looked around and saw alot of suggestions to add a <script> tag, But it doesn't seem to work. Where am I going wrong?

Code.gs

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

        return HtmlService.createHtmlOutputFromFile('confirmation'); 
    }

HTML file

<!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>
question from:https://stackoverflow.com/questions/65877955/how-to-automatically-close-a-browser-tab-after-it-opens-when-i-run-a-get-request

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The short answer is this cannot be done. please see @TheMaster's comment.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...