Confirming When Exiting Without Saving
-
Hi, I need help with confirming when exiting without saving. I am using ASP.NET 2.0. I have an .aspx page with a couple of input controls. Then there is a submit button and a cancel button. I have a javascript method that checks if an input field has been changed or not. When the cancel button is clicked this javascript method is fired and displays a pop up message to the user. The thing that I am having difficult to implement is if data in the input was changed, but the user doesn't click the cancel button, but just clicks on another link to another page. If this is the case then I need the javascript method also to fire where the user go to a different page. Please can someone advise? Regards Brendan
-
Hi, I need help with confirming when exiting without saving. I am using ASP.NET 2.0. I have an .aspx page with a couple of input controls. Then there is a submit button and a cancel button. I have a javascript method that checks if an input field has been changed or not. When the cancel button is clicked this javascript method is fired and displays a pop up message to the user. The thing that I am having difficult to implement is if data in the input was changed, but the user doesn't click the cancel button, but just clicks on another link to another page. If this is the case then I need the javascript method also to fire where the user go to a different page. Please can someone advise? Regards Brendan
-
i have used onbeforeunload event to confirm leave, i.e.
window.onbeforeunload = function() { if (modified) return "Unsaved changes. Are you sure you want to leave?" }
Thanks for this, but I am not sure where to put this in. Here is a basic representation of my code: var isDirty = false; function checkForChange(msg) { if (isDirty) return confirm(msg); else return true; } I hope you can help me on this. Thanks Brendan
-
Thanks for this, but I am not sure where to put this in. Here is a basic representation of my code: var isDirty = false; function checkForChange(msg) { if (isDirty) return confirm(msg); else return true; } I hope you can help me on this. Thanks Brendan
Hi, See the modified example below. I would suggest to use temporary functions to avoid javascript memory leaks. I hope this makes sense.
var isDirty = false; // this is the message we will show to confirm var default_message = "You have made changes to the data since last saving. If you continue, you will lose these changes."; var checkForChange = function(msg) { if (isDirty) return confirm( !msg ? default_message : msg ); } window.onbeforeunload = function() { return default_message; }