Prompting A User To Salve Changes Earlier Leaving A Page Using Jquery
The commencement footstep is to know when the shape is ‘dirty’ i.e. when a user has made whatsoever modify to the shape that has non been saved. There are a diverse ways to know that a shape is dirty, exactly I chose to declare a global variable called ‘isDirty’.
There are many other ways to accomplish this. If you lot know whatsoever other agency to accomplish this, produce part here.
Ref: http://www.prosoxi.com/2012/06/21/jquery-method-to-prompt-a-user-to-save-changes-before-leaving-page/ Sumber http://developer-paradize.blogspot.com
var isDirty = false; $(document).ready(function() { //save all the input values to cheque subsequently $('#myform input').each(function() { $(this).data('original', $(this).val()); }); $(window).bind('beforeunload', function(){ //to update the muddied flag when at that spot is a dissimilar shape values $('#myform input').each(function() { if ($(this).data('original') != $(this).val()) { isDirty = true; } }); if (isDirty) { provide 'You haven\'t saved your changes.'; } }); });This method volition honour if the user has made whatsoever changes inwards the shape in addition to warning the confirmation dialog. In this way, you lot tin protect a user from leaving the page if at that spot is modify inwards the form.
There are many other ways to accomplish this. If you lot know whatsoever other agency to accomplish this, produce part here.
Ref: http://www.prosoxi.com/2012/06/21/jquery-method-to-prompt-a-user-to-save-changes-before-leaving-page/ Sumber http://developer-paradize.blogspot.com
Comments
Post a Comment