onunload not working in Chrome and safari

后端 未结 4 1028
不知归路
不知归路 2020-12-10 04:31

I have parent page and child page. In child page body tag i have below code.



        
相关标签:
4条回答
  • 2020-12-10 04:44

    Maybe try onbeforeunload event?

    0 讨论(0)
  • 2020-12-10 04:55

    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.

    0 讨论(0)
  • 2020-12-10 04:55

    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
                });
        });
    
    0 讨论(0)
  • 2020-12-10 04:55

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

    0 讨论(0)
提交回复
热议问题