Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thehunmonkgroup/6bee8941a49b86be31a787fe8f4b8cfe to your computer and use it in GitHub Desktop.
Save thehunmonkgroup/6bee8941a49b86be31a787fe8f4b8cfe to your computer and use it in GitHub Desktop.
/**
* iOS doesn't support beforeunload, use pagehide instead.
* NOTE: I tried doing this detection via examining the window object
* for onbeforeunload/onpagehide, but they both exist in iOS, even
* though beforeunload is never fired.
*/
var iOS = ['iPad', 'iPhone', 'iPod'].indexOf(navigator.platform) >= 0;
var eventName = iOS ? 'pagehide' : 'beforeunload';
window.addEventListener(eventName, function (event) {
// Do the work...
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment