title: window.onbeforeunload - Only show warning when not submitting form
body: <p>I am using window.onbeforeunload to prevent the user from navigating away after changing values on a form. This is working fine, except it also shows the warning when the user submits the form (not desired).</p>
  
  <p>How can I do this without showing the warning when the form submits?</p>
  
  <p>Current code:</p>
  
  <pre><code>var formHasChanged = false;
  
  $(document).on('change', 'form.confirm-navigation-form input, form.confirm-navigation-form select, form.confirm-navigation-form textarea', function (e) {
      formHasChanged = true;
  });
  
  $(document).ready(function () {
      window.onbeforeunload = function (e) {
          if (formHasChanged) {
              var message = "You have not saved your changes.", e = e || window.event;
              if (e) {
                  e.returnValue = message;
              }
              return message;
          }
      }
  });
  </code></pre>