EDIT: My question is different from the 'supposedly duplicate' because mine is checking how to not trigger off an event when a link is clicked, the other question is about how to detect changes in a form.
I am using a function (taken from here) to detect any changes made to a form before leaving the page, this works fine however it also triggers off when I click the save button as I am using the onbeforeunload
event to fire of the function and I want to prevent this from happening when I click my save button.
Here is my event:
window.onbeforeunload = function (e) {
e = e || window.event;
if (formIsDirty(document.forms[0])) {
// For IE and Firefox
if (e) {
e.returnValue = "You have unsaved changes.";
alert("You have unsaved changes.");
}
// For Safari
return "You have unsaved changes.";
alert("You have unsaved changes.");
}
};
How can I prevent this event from firing when this particular save link is clicked?
Link:
<a id="ctl00_ContentPlaceHolder1_lbtnSave" href='/save'>
<img id="ctl00_ContentPlaceHolder1_Image5" class="imgvalign" src="../../images/icons/save.gif"> Save
</a>