Confirm leaving of page unless leaving by form submission
<p>I have a page containing a form where I would like to prompt the user to confirm to leave the page if they have started entering form data unless, of course, they leave the page by submitting the form. How can I bypass the below code if the form has been submitted causing the page change?</p>

<pre><code>$(document).ready(function(){
        window.onbeforeunload = function () {

                return "If you leave this page before submitting your information to us you will need to reenter it again.";

        }
    })
</code></pre>
