Detect Close Browser in ASP.NET
<p>I have a ASP.NET web app with a MasterPage and contents page, from the MasterPage when I click a MenuItem to open a new aspx Page. if I want to close the new page browser tab, I want to show a popup or a dialog that alert the user that he is closing the browser tab. I used the following code in the new aspx page:</p>

<pre><code>&lt;script type="text/javascript"&gt;
    $(window).bind("beforeunload", function () {
        $(window).unbind("beforeunload");
        return confirm("Do you really want to close?")
    })
&lt;/script&gt;
</code></pre>

<p>the problem is that if i press also other buttons than the browse closeTab the method works. i would like to know how can i avoid it.</p>

<p>thanx in advance.   </p>
