捕获浏览器关闭事件 [英] Catch Browser close event
本文介绍了捕获浏览器关闭事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,我需要在用户单击浏览器关闭按钮但关闭/关闭浏览器时调用一个函数,我已经尝试了很多类似
的方法
1)在正文标签OnUnload()中,但每次回发时都运行,并且不起作用
我还尝试抓住浏览器关闭按钮
2)
Hi guys i needed to call a function when user clicks on browser close buton/closing of browser, i have tried many things like
1)In body tag OnUnload() but it runs every time when post back and its not working
i also tried to catch Browser close button
2)
function doUnload()
{
if (window.event.clientX < 0 && window.event.clientY < 0)
{
alert("Window is closing...");
}
} its also not working
...
<body önunload="doUnload()">
因此,任何技巧或逻辑都会受到高度重视
谢谢
so any trick or logic will be highly apreciated
Thanks
推荐答案
如果您提供了卸载功能,它将无法在IE浏览器中使用...
为此,请在"onbeforeunload"中提供该功能,如....
if u give in unload function it will not work in IE browser...
for that give that function in "onbeforeunload" like....
<body onbeforeunload="javascript:alert(''window is closing...'');">
我发现您的代码有两个可能的问题.
我相信如果事件触发时,如果鼠标位于浏览器的客户端窗口之外,则IE返回null
.因此,您的条件将评估为false
.
另外,如果要通过单击退出"按钮来关闭浏览器,那么<c2>将是一个正值,就像您在0, 0
点右侧一样.
I see two possible problems with your code.
I believe that IE returnsnull
if the mouse is outside the browser''s client window when the event fires. Your conditional would therefore evaluate tofalse
.
Also, if you are closing the browser by clicking on the Exit button, thenwindow.event.clientX
would be a positive value, as you are to the right of the0, 0
point.
hi ,
为此,请尝试以下行.
Try this lines for that.
这篇关于捕获浏览器关闭事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文