Sunday, October 14, 2012

Jquery to warn userspage Losing data when navigating away from form

Using JQuery to Warn Users About Losing Data When Navigating Away from Form

 
 
$(document).ready(function() { 
     
     $(':input',document.myForm).bind(
         "change", function() { 
              setConfirmUnload(true);
         }
     ); // Prevent accidental navigation away

});
 
function setConfirmUnload(on) {
    
     window.onbeforeunload = (on) ? unloadMessage : null;

}

function unloadMessage() {
    
     return 'You have entered new data on this page.' +
        ' If you navigate away from this page without' +           
        ' first saving your data, the changes will be' +
        ' lost.';

} 

No comments:

Post a Comment