如何使用javascript检查打开的窗口是否关闭?
有没有办法检测我打开的弹出窗口是否关闭如何使用javascript检查打开的窗口是否关闭?,javascript,Javascript,有没有办法检测我打开的弹出窗口是否关闭 <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.ope
<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>
//子窗口引用的全局变量
新窗口;
//生成并填充新窗口
函数makeNewWindow(){
//确保它尚未打开
新建窗口=窗口。打开(“http://www.google.com“,”子“,”状态,高度=200,宽度=300”);
}
函数checkWindow(){
if(newWindow.closed){
文件。写入(“窗口已关闭”);
}
}
检查窗口();
当我关上打开的窗户时,我想要那个。函数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);