Custom dialog box to get confirmation when browser tab is closed
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/2132760/how-to-ask-confirmation-when-closing-a-window">How to ask confirmation when closing a window?</a>  </p>
</blockquote>



<p>I would like to display a confirmation box and a custom message when the browser tab is closed. Users can click OK to actually close the tab, and CANCEL to stay on the page.</p>

<p>The following is my code. Can someone tell me how I can make it work?</p>

<pre><code>    window.onbeforeunload = function (e) {
    e = e || window.event;

    // For IE and Firefox prior to version 4
    if (e) {
        e.returnValue = 'ARE you sure?';
    }

    // For Safari
    return 'ARE you sure?';
};
</code></pre>
