I'm trying to show a prompt message in case user trying to refresh the page. I used window.onbeforeunload and it's working fine on other browsers BUT not Mobile Safari.
I'm trying to use window.onunload for Mobile Safari, I can show the prompt message, but cannot prevent refreshing page.
Below is the code
<script>
var iOS = ( navigator.userAgent.match(/(iPad|iPhone|iPod)/g) ? true : false );
if(iOS){
window.onunload = function() {
var test = confirm("Are you sure you want to leave this page");
if(!test){
return false;
}
}
}
I also tried the pagehide event, can show the prompt but still cannot prevent refreshing page Below is the code
<script>
window.addEventListener("pagehide", function(){
var test = confirm("Are u sure you want to leave this page aaaaaaaaaaaaa");
if(!test){
return false;
}
},false);
</script>