6

I'm trying to catch beforeunload, unload, pagehide events on iPhone Safari (602.1) IOS 10.3.3. But it seems that on iPhone these events don't fire, and the funny part is that on iPad which has same versions of browser and IOS, the events do fire. The only difference that I noticed was that iPad gives you the tab option but iPhone doesn't. Is there any way to catch these events on iPhone IOS 10.3.3?

Note: These events do fire on iPhone IOS 8.4.1.

ato
  • 61
  • 1
  • 3
  • [iPhone doesn't support onbeforeunload](https://stackoverflow.com/questions/6903457/is-the-onbeforeunload-event-not-supported-on-iphone), [unload is deprecated](https://stackoverflow.com/questions/4127621/is-there-any-way-to-use-window-onbeforeunload-on-mobile-safari-for-ios-devices), so the question is,how do you use `.pagehide`? (which, apparently, should work) – Adelin Nov 06 '17 at 11:20
  • Hello Adelin , actually the main problem is that all these events are not working with the IOS 10.3.3 safari , as you said i have read that beforeunload, unload wont work but way does pagehide have the same problem ? I'am using the pagehide as below , window.onpagehide = function() { return "abort"; } or function abort() { return "abort"; } window.addEventListener("pagehide", abort); I have also document.addEventListener("pagehide", abort); but these wont fire on Iphone. – ato Nov 06 '17 at 11:39
  • Possible duplicate of [Is the onbeforeunload event not supported on iPhone?](https://stackoverflow.com/q/6903457/1255289) – miken32 Nov 18 '17 at 06:45

1 Answers1

4

I use event pagehide with (partial) success, see supported Events in Apple Guides.

The only situation that pagehide does not work is on iPhone 10, and when the website is stored to the application 'springboard'. The web application (build with Vuejs) looks like a native App. Leaving the 'app' does not fire pagehide. On older iPhones and iPads in the same situation, pagehide fires.

window.addEventListener('pagehide', () => { // do something }

  • Very useful; but what a billion dollar mistake IOS devices/Apple IDevices have made by curious behavior. work or not work? can't answer. A lot of valid use cases, analytics, sessions accuracy are lost. Hope they give the support sooner in all patched and newer versions of IOS. It's must have. – webblover Apr 16 '20 at 06:45