title: Browser confirm closing: cancel button also closes the browser
body: <p>I have a form in my page. I want a confirm close when someone closes the browser. If user clicks the OK button, the form should be submitted and browser should be closed. And if the user clicks the cancel button/close the confirm box, nothing should happen. Here is my code:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;script language="JavaScript"&gt;
  function closeEditorWarning(){
  if(confirm('Are you sure want to close this window'))
  {
  document.quiz.submit();
  }
  }
  window.onbeforeunload = closeEditorWarning;
  &lt;/script&gt;
  &lt;form name="quiz" action="Hello.html" method="get" target="_blank"&gt;
    First name: &lt;input type="text" name="fname"&gt;&lt;br&gt;
    Last name: &lt;input type="text" name="lname"&gt;&lt;br&gt;
    &lt;input type="submit" value="Submit"&gt;
  &lt;/form&gt;
  &lt;p&gt;Click on the submit button, and the input will be open "hello.html".&lt;/p&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>But the dilemma is that , i am getting my browser closed on click of cancel button/ closing the confirm box as well. Please help.</p>