title: How can I override the OnBeforeUnload dialog and replace it with my own?
body: <p>I need to warn users about unsaved changes before they leave a page (a pretty common problem).</p>
  <pre><code>window.onbeforeunload = handler
  </code></pre>
  <p>This works but it raises a default dialog with an irritating standard message that wraps my own text. I need to either completely replace the standard message, so my text is clear, or (even better) replace the entire dialog with a modal dialog using jQuery.</p>
  <p>So far I have failed and I haven't found anyone else who seems to have an answer. Is it even possible?</p>
  <p>Javascript in my page:</p>
  <pre><code>&lt;script type=&quot;text/javascript&quot;&gt;   
      window.onbeforeunload = closeIt;
  &lt;/script&gt;
  </code></pre>
  <p>The closeIt() function:</p>
  <pre><code>function closeIt()
  {
    if (changes == &quot;true&quot; || files == &quot;true&quot;)
    {
        return &quot;Here you can append a custom message to the default dialog.&quot;;
    }
  }
  </code></pre>
  <p>Using jQuery and jqModal I have tried this kind of thing (using a custom confirm dialog):</p>
  <pre><code>$(window).beforeunload(function () {
      confirm('new message: ' + this.href + ' !', this.href);
      return false;
  });
  </code></pre>
  <p>which also doesn't work - I cannot seem to bind to the <code>beforeunload</code> event.</p>