gpt4 book ai didi

javascript - 如何检查打开的窗口是否已用 javascript 关闭?

转载 作者:行者123 更新时间:2023-12-02 19:56:26 25 4
gpt4 key购买 nike

有什么方法可以检测我打开的弹出窗口是否关闭?

<script type="text/javascript">
// global variable for subwindow reference
var newWindow;
// generate and fill the new window
function makeNewWindow() {
// make sure it isn't already opened
newWindow = window.open("http://www.google.com","sub","status,height=200,width=300");

}

function checkWindow() {
if(newWindow.closed){
document.write("Window has closed.");
}
}
</script>
<form>
<input type="button" value="Create New Window" onclick="makeNewWindow();" />
<script>
checkWindow();
</script>
</form>

我希望当我关闭打开的窗口时。函数 checkWindow() 在屏幕上打印“窗口已关闭”。请建议我一些帮助代码。提前致谢

最佳答案

  var win = window.open('http://www.google.com','google','width=800,height=600,status=0,toolbar=0');   
var timer = setInterval(function() {
if(win.closed) {
clearInterval(timer);
alert('closed');
}
}, 1000);

关于javascript - 如何检查打开的窗口是否已用 javascript 关闭?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8558288/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com