onunload not working in Chrome and safari
I have parent page and child page. In child page body tag i have below code.
<body onunload="window.g_autoclosed=true;if(window.opener&&window.opener.NavModelessClose){window.opener.NavModelessClose(window,false);}">
when i click on button in parent page, child page should close and call the onunload event.
The unload event is raising correctly in IE and FF. But it is 开发者_Go百科not raising in chrome and safari.
Please help me.
Modern WebKit browsers don't necessarily fire the unload
event at the moment where the page is hidden. This is done in order to allow improved caching.
You might consider replacing the use of unload
with the pagehide
event.
See this blog post for an in-depth discussion.
Unload works in modern browsers, but for example you cant launch an alert. See: http://bugs.jquery.com/ticket/10509
Also if you want to use $.get or $.post in unload, is better that you use $.ajax with async=false.
Ex:
$(window).unload(function() {
$.ajax({
url: '/some_url.htm',
async: false
});
});
Maybe try onbeforeunload
event?
yea onbeforeunload attached to window (or inner window of the child page) should do it
精彩评论