12

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.

Semyazas
  • 2,101
  • 14
  • 14
prasanth
  • 121
  • 1
  • 1
  • 3
  • possible duplicate of http://stackoverflow.com/questions/803887/can-i-pop-up-a-confirmation-dialog-when-the-user-is-closing-the-window-in-safari –  Jul 27 '11 at 11:36

4 Answers4

12

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.

Joachim Sauer
  • 302,674
  • 57
  • 556
  • 614
7

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
            });
    });
user1769609
  • 93
  • 1
  • 4
5

Maybe try onbeforeunload event?

zatatatata
  • 4,761
  • 1
  • 20
  • 41
1

yea onbeforeunload attached to window (or inner window of the child page) should do it

Assaf Moldavsky
  • 1,681
  • 1
  • 19
  • 30