Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In the inline code

<script language="javascript" type="text/javascript">
window.onbeforeunload = WindowCloseHanlder;
    function WindowCloseHanlder()
        {
           alert("ur closing broswer");
         
            PageMethods.AbandonSession();
        }
</script> 

 <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">

In the code behind(class file)

 [WebMethod]
        public static void AbandonSession()
        {
            HttpContext.Current.Session.Abandon();
            HttpContext.Current.Application.RemoveAll();
        }


But its work in IE Browser not in Mozilla and chrome
Posted
Updated 7-Jan-14 18:21pm
v2

1 solution

Here is a code that works in Chrome & Mozilla.

window.onbeforeunload = function(e){
    var msg = 'Are you sure you want to close?';
    e = e || window.event;

    if(e)
        e.returnValue = msg;

    return msg;
}


Hope this helps!
Cheers
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900