Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 not raising in chrome and safari.

Please help me.

like image 440
prasanth Avatar asked Jul 27 '11 11:07

prasanth


People also ask

What is the difference between Onbeforeunload and Onunload?

One significant difference (other than cancelability) between the onbeforeunload and onunload is that the former is triggered for download links and the latter is not. Example: <a href="https://somewhere.com/thething.zip">download</a> will trigger the onbeforeunload handler, but not the onunload .

What triggers Onbeforeunload?

The beforeunload event is fired when the window, the document and its resources are about to be unloaded. The document is still visible and the event is still cancelable at this point. This event enables a web page to trigger a confirmation dialog asking the user if they really want to leave the page.

Can I use Onbeforeunload?

This feature is deprecated/obsolete and should not be used.

What is window Onunload?

onunload occurs when the user navigates away from the page (by clicking on a link, submitting a form, closing the browser window, etc.). Note: The onunload event is also triggered when a user reloads the page (and the onload event).


1 Answers

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.

like image 138
Joachim Sauer Avatar answered Sep 27 '22 18:09

Joachim Sauer