I would like display a popup when the user close tab or refresh page on ios to prevent him he will lose his datas. I have seen unload
is deprecated and I have to use pagehide
event but it seems the both don't work on safari and even chrome.
My code is:
window.addEventListener("pagehide", function (evt) {
return confirm("Vous allez perdre toutes vos modifications");
}, false);
The problem is the page refresh even if I click on cancel button, and the popup doesn't appear if I close the tab.
i tried this code too for Chrome mobile (desktop work fine) but the both don't work with his browser
window.addEventListener("beforeunload", function (e) {
if (closeWindow) {
var message = 'Toutes vos modifications seront perdues';
if (typeof evt == 'undefined') {
evt = window.event;
}
if (evt) {
evt.returnValue = message;
}
return message;
}
}, false);