Why is jQuery unload not working in chrome and safari?

后端 未结 7 781
逝去的感伤
逝去的感伤 2020-12-05 17:42

unload function in jQuery works fine in Firefox but not in chrome and safari. please check this fiddle in chrome and Firefox. http://jsfiddle.net/jeevankk/Gywnw/2/ . Alerts

相关标签:
7条回答
  • 2020-12-05 18:24

    "refresh" action in the Firefox does not fire the unload event.

    We should use onbeforeunload instead.

    Confirm with Firefox version 47, Mac OS X

    0 讨论(0)
  • 2020-12-05 18:29

    the unload function of jquery has some problem with browsers..refer the following link http://bugs.jquery.com/ticket/5538

    can you elaborate on the problem so that we can find some work around??

    0 讨论(0)
  • 2020-12-05 18:30

    This should work to show a confirmation when the users leaves, this is also not part of any standard.

    $(window).on('beforeunload ',function() {
        return 'Are you sure ?';
    });
    
    0 讨论(0)
  • 2020-12-05 18:35

    This is because the unload event is not part of any standard

    https://developer.mozilla.org/en/DOM/window.onunload

    check the bottom of the page i just linked to.

    0 讨论(0)
  • 2020-12-05 18:38

    I found Joseph's comment as the correct answer, So posting this answer.

    Dialogs are blocked/prevented during "beforeunload" (with exception to the beforeunload prompt) and "unload" events. Can be confirmed by checking your console.

    0 讨论(0)
  • 2020-12-05 18:40

    you can use onfocusout on the body .. but i wouldn't recommend if you are trying to use something like an alert, on this operation, asking the user not to leave your page ..

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