Preventing onbeforeunload dialogs in IE9

前端 未结 2 733
抹茶落季
抹茶落季 2021-01-25 05:01

I\'m having an issue in IE9 with onbeforeunload -- when the code below is run it repeatedly brings up a dialog asking if you want to stay or leave the page.

I modified

相关标签:
2条回答
  • 2021-01-25 05:09

    You cannot send an AJAX request while the page is unloading as most browsers block it. You should ask the user to stay on the page if there is dirty data. That's all you should do from your onbeforeunload handler

    Try your code without calling $.post and it should behave as expected

    0 讨论(0)
  • 2021-01-25 05:13

    The only thing you are allowed to do in an onbeforeunload handler is display a dialog. You specifically don't get any extra time to perform tasks which may take time to complete, like firing off HTTP requests — the user has asked to leave your site; aside from asking them politely whether they want to stay, you aren't allowed to make them stay (even while you clean up).

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

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