我希望在几秒钟后关闭窗口,并使用html

时间:2018-11-15 06:09:26

标签: html google-apps-script google-sheets

<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
Please wait for few seconds, until this `Dialogue Box` closes. This waiting time is required for the Page to Load Completely. Thank you.<input type="button" value="Close" onclick="google.script.host.close()" />
</body>
</html>

代替用户点击Close button, 我希望onclick操作在几秒钟后自动发生。请帮忙。

1 个答案:

答案 0 :(得分:1)

由于安全问题,关闭窗口的操作被禁用,除非使用相同的脚本创建了该窗口。但是,如果要在特定时间后单击该按钮,请使用setTimeout()函数。

<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
Please wait for few seconds, until this `Dialogue Box` closes. This waiting time is required for the Page to Load Completely. Thank you.
<input type="button" value="Close" id="myButtonId" onclick="myfunction()" /><br>

<script type="text/javascript">

    setTimeout(function () {document.getElementById("myButtonId").click();}, 3000);

    function myfunction(){

        alert("clicked");
    }


</script>
</body>
</html>