title: Display modal form before user leaves page
body: <p>I've used <code>window.onbeforeunload</code> to display a custom message when a user attempts to leave a site.</p>
  
  <p>Example:</p>
  
  <pre><code>window.onbeforeunload = function(){
    if(some_condition){
      return "Are you sure you want to navigate away from this page?\nAll unsaved changes will be lost.";
    }
  };
  
  
  +--------------------------------------------------------+
  | Are you sure you want to navigate away from this page? |
  | All unsaved changes will be lost.                      |
  |                                                        |
  |          [ Yes ]  [ Cancel ]                           |
  +--------------------------------------------------------+
  </code></pre>
  
  <p>However, I'd like to enhance this a bit. If possible, I'd like to use a custom modal form instead of the generic popup. </p>
  
  <p>Is there a way to do this?</p>