11

So, I've got a handy little bit of functionality in place in a jQuery Mobile app that lets the user know if he/she is navigating away from the page, as this will trigger a log off. In simplified form:

$(window).bind('beforeunload', function() {
  return "Navigating away from this page will log you off. Are you sure you want to continue?";
});

$(window).unload(function() {
  logoff();
});

This works just great in both Safari and Chrome on my laptop. However, it doesn't appear to work on the iPhone simulator.

Does the mobile browser included in iOS (I know it's Safari, but presumably a different version) simply not support the beforeunload event? Is this true in general for mobile devices (in particular, Android)?

Dan Tao
  • 125,917
  • 54
  • 300
  • 447
  • Does this answer your question? [window.onbeforeunload not working on the iPad?](https://stackoverflow.com/questions/3239834/window-onbeforeunload-not-working-on-the-ipad) – Mišo Dec 05 '19 at 09:41
  • The iPhone indeed does not support `onbeforeunload` This question has a possible workaround: https://stackoverflow.com/questions/4127621/is-there-any-way-to-use-window-onbeforeunload-on-mobile-safari-for-ios-devices – John Douthat Aug 02 '11 at 05:33

0 Answers0