博客网 >

跨浏览器抓取页面窗口关闭事件
作者:分类:默认分类标签:

this workround is very useful for multi-browser development. Imagine that if you want to capture close event for both Firefox and IE, this is just what you are seeking.

with Ajax, you can simply call server side handle, this way, the whole application turns to be meaningful:)

below is the solution to capture close event both for Firefox and IE, this article comes from here .

I found this other solution to this problem that it seems very cool to me! :cool:
Advantages:
- Do not use polling.
- Recognize if child window is closed or is been updated by user .
- Found on IE and Mozilla Firefox.
PARENT WINDOW

<html>
<head>
<title>Main window</title>
<script type="text/javascript">
var childWindow = null;
function openChildWindow() {
childWindow = window.open('child.html','Childwindow','status=0,toolbar=0,menubar=0,resizable=0,scrollbars=1,top=50 ,left=50,height=375,width=650');
}
function checkChildWindowStatus() {
if (!childWindow || childWindow.closed) {
alert("Crazy flyer child window seems to be closed! :P");
}
}
function childWindowUnloadNotification() {
// Here we get notification from child window. Here we can decide if suck notification is
// raised because user close child window, or because user is playing with F5 key.
// NOTE: We can not trust on "onUnload" event of child window, because if user reload or refresh
// such window in fact he is not closing child. (However "onUnload" event is raised!)
setTimeout('checkChildWindowStatus()', 50);
}
</script>
</head>
<body>
Press bottom to open child window<br />
<input type="button" value="Open child window" onclick="javascript:openChildWindow();"/>
</body>
</html>
CHILD WINDOW

<html>
<head>
<title>Crazy flyer child window</title>
<script type="text/javascript">
function unloadNotification() {
// Raise unload notification to parent window
window.opener.childWindowUnloadNotification();
}
</script>
</head>
<body onunload="javascript:unloadNotification();">
Body of the creazy child window<br />
</body>
</html>

<< asp.net程序全局异常处理 / Globalization of... >>

专题推荐

不平凡的水果世界

不平凡的水果世界

平凡的水果世界,平凡中的不平凡。 今朝看水果是水果 ,看水果还是水果 ,看水果已不是水果。这境界,谁人可比?在不平凡的水果世界里,仁者见仁,智者见智。

中国春节的那些习俗

中国春节的那些习俗

正月是农历新年的开始,人们往往将它看作是新的一年年运好坏的兆示期。所以,过年的时候“禁忌”特别多。当然,各个地方的风俗习惯不一样,过年的禁忌也是不一样的。

评论
0/200
表情 验证码:

gisman

  • 文章总数0
  • 画报总数0
  • 画报点击数0
  • 文章点击数0
个人排行
        博文分类
        日期归档