codedance / jquery.AreYouSure

A light-weight jQuery "dirty forms" Plugin - it monitors html forms and alerts users to unsaved changes if they attempt to close the browser or navigate away from the page. (Are you sure?)
508 stars 145 forks source link

Safari Mobile - how to display prompt message and prevent refreshing page without clicking any links #70

Closed saigitaccount closed 9 years ago

saigitaccount commented 9 years ago

I'm trying to show the prompt message and prevent refreshing page if user's trying to refresh the page.

I would like the message can be shown if user hasn't click on any links yet, just refresh the page.

So I made something similar to ays-beforeunload-shim.js like this:

var iOS = ( navigator.userAgent.match(/(iPad|iPhone|iPod)/g) ? true : false ); if(iOS){

window.onunload = function() {              
 var response = $(window).triggerHandler('beforeunload', response);
if (response && response != "") {
    var msg = response + "\n\n"
      + "Press OK to leave this page or Cancel to stay!!!.";
    if (!confirm(msg)) {
      return false;
    }
  }
}

}

I can see the message but cannot prevent reloading page even I clicked "Cancel" on the prompt.

Is there anyway to make this done?

codedance commented 9 years ago

Closing off this old issue. It should be addressed with the project's shim.