I recently figured out that the onbeforeunload
event is not supported on IOS devices. I also did some research and tried other events like the pagehide
event but it also didn't work. What I'm trying to achieve is to save some data in the local storage before leaving the page. It works fine for windows and android but not for IOS devices. This is the code:
window.onbeforeunload = function(e){
save_something_in_local_storage();
};
I could also identify IOS devices with:
var iOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
Trying other events like for example pagehide also won't work:
window.addEventListener("pagehide", function(evt){
alert('pagehide');
}, false);
Anyone knows a workaround for IOS?