window.onclose函数 [英] window.onclose function

查看:766
本文介绍了window.onclose函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用此功能在我的窗口关闭时调用。

I use this function to call on my window close.

这是确认框弹出窗口。

if(confirm("Sure you want to close the window");
{
     // yes return to submit function
}
else
{
  // no return to Other call function
}

window.onclose = function()
{
  alert('yes');
}

用X关闭右上角的窗口符号我需要返回false。我正在尝试使用这个 window.onclose 函数,但它没有弹出。

On Close of window on the top right corner with X symbol I need to return false. I am trying to use this window.onclose function but its not poping up.

有人可以帮帮我吗?

推荐答案

不幸的是,弹出窗口没有任何你可以听的关闭事件但是有一个关闭的属性,当窗口关闭时是真的。解决这个问题的一个解决方案是启动计时器并每秒检查子窗口的关闭属性,并在窗口获取时清除计时器这是代码:

Unfortunately the popup window does not have any close event that you can listen to but there is a closed property that is true when window gets closed. A solution to get around this problem is to start a timer and check the closed property of the child window every second and clear the timer when the window gets closed. Here is the code:

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); 

这篇关于window.onclose函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆