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.
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.
Share Improve this question edited Nov 8, 2017 at 7:37 ato asked Nov 6, 2017 at 10:52 atoato 611 silver badge3 bronze badges 3-
iPhone doesn't support onbeforeunload, unload is deprecated, so the question is,how do you use
.pagehide
? (which, apparently, should work) – Adelin Commented Nov 6, 2017 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 Commented Nov 6, 2017 at 11:39
- Possible duplicate of Is the onbeforeunload event not supported on iPhone? – miken32 Commented Nov 18, 2017 at 6:45
1 Answer
Reset to default 4I 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
}