How to check a dirty flag
I was wondering what the best way is to check if a page is dirty if the user chooses to navigate away from it. For example, there is a registration form and the user enters all their information. Then accidentally clicks on the link to navigate away from it.
I found this on the internet where it checks to see if the page is dirty if a person makes changes to any form input values.
<script type="text/javascript">
var isDirty = false;
var msg = 'You haven\'t saved your changes.';
$(document).ready(function(){
$(':input').change(function(){
if(!isDirty){
isDirty = true;
}
});
window.onbeforeunload = function(){
if(isDirty){
return msg;
}
};
});
</script>
So this works great. But how can I exclude some of the links that pop up? Is there a better way to do this?
+3
source to share