title: I want to call function on window unload
body: <p>I am trying to display confirmation box using <code>window.confirm</code> on window unload event.</p>
  <p>If a user clicks on the <kbd>OK</kbd> button on confirmation box then I want to call one function and if user clicks the <kbd>CANCEL</kbd> button then window should be get closed.</p>
  <p>My code is:</p>
  <pre><code>&lt;script&gt;
          function confirmit(){
                  var result=window.confirm(&quot;Are you sure?&quot;);
                  if(result) {
                      // close all child windows
                  } else{
                      // window should not get close
                  }
              }
  &lt;/script&gt;
  &lt;body onunload='confirmit();' &gt;
  </code></pre>
  <p><strong>But the problem is if I click on <kbd>CANCEL</kbd> button, window is getting closed.</strong></p>
  <p>Please help me.</p>