Question

I'm detecting form changes in a page, and so i've handled

$('#element').change(function(){
metaDataChange = true;
});

so that when the user leaves the page and a change was made in an input in a form. He/she will be alerted whether to leave or to stay on the page, just like in Facebook where you try to post a status and then you leave the page, a dialog box will be prompted giving you options to either leave or stay in the page.

$(window).on('beforeunload', function() {

    if(metaDataChange === true || basicInfoChange === true){
        return "You have unsaved changes, do you want to leave without saving?";       
    }
});

The code above works well however.. i want to exclude the submit button for this. Because when i click "submit" and the behavior of the submit button means redirecting to another page. The user is prompted again with the same message when in fact he/she intends to save his/her changes.

How do i exclude the submit button from being caught in the beforeunload event of the window? I can hardly explain this... i hope it can be understood..Thanks!

Was it helpful?

Solution

$('#submitButton').click(function(){
metaDataChange = false;
...redirecting 
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top