window.onclose函数 [英] window.onclose function
问题描述
我使用此功能在我的窗口关闭时调用。
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屋!