Check if link is clicked in JavaScript
<p>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. </p>

<p>I am using a function (<a href="https://stackoverflow.com/questions/155739/detecting-unsaved-changes">taken from here</a>) 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 <code>onbeforeunload</code> event to fire of the function and I want to prevent this from happening when I click my save button.</p>

<p>Here is my event:</p>

<pre><code>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.");
    }
};
</code></pre>

<p>How can I prevent this event from firing when this particular save link is clicked?</p>

<p>Link:</p>

<pre><code>&lt;a id="ctl00_ContentPlaceHolder1_lbtnSave" href='/save'&gt;
&lt;img id="ctl00_ContentPlaceHolder1_Image5" class="imgvalign" src="../../images/icons/save.gif"&gt; Save
 &lt;/a&gt;
</code></pre>