title: confirm() on window.onbeforeunload
body: <p>I want to show a confirmation dialog if the user wants to leave the page with unsaved form data. What I have is:</p>
  
  <pre><code>window.onbeforeunload = function() {
      if (not_saved) if (confirm('Changes will not be saved')) return true;
      return false;
  }
  </code></pre>
  
  <p>But no matter what the user clicks, the result is the same - the stupid hardcoded dialog box that asks them whether they want to leave the page or stay on page. What I want to ask them is whether they want to stay or leave, and if they want to stay nothing happens, if they want to leave, they leave. Is this even possible? I can see how browsers want to limit what websites can do about keeping the users on the page, but I think I've seen some websites (Google Docs I think) having nice civilized dialog boxes.</p>