Last active
May 13, 2020 21:41
-
-
Save thehunmonkgroup/6bee8941a49b86be31a787fe8f4b8cfe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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