?

Log in

 

Event on closing browser window - Web Developer

About Event on closing browser window

Previous Entry Event on closing browser window Mar. 11th, 2013 @ 04:33 pm Next Entry
Hi,
I am working on a web site (ASP.NET, FW4) which has a secure section (login required).
I would like to clear the session variables when customer closes the browser.
To achieve that I have placed a hidden button on the MasterPage (have tested, it works) and then trying to call the ASP method using JavaScript.
    <script type="text/javascript">
      window.onbeforeunload = function()
      {
         CustomLogoff();
      }
      function CustomLogoff()
      {
         var button1 = document.getElementById('<%=hiddenLogoutButton.ClientID %>');
         button1.click();
      }
    </script>
    <asp:Button runat="server" ID="hiddenLogoutButton" 
         Text="Invisible Logout Button" Visible="false" 
         onclick="hiddenLogoutButton_Click" />

(Also tried to put this call into body tag: <body onbeforeunload='CustomLogoff()'>)

CustomLogoff is not being called. Thought when calling it like this:

<input type="buton" onClick="CustomLogoff()" value="logoff">

It works fine (on button click of course).

Is there a way to make it work on browser closing too?
Leave a comment
[User Picture Icon]
From:valera
Date:March 11th, 2013 08:37 pm (UTC)
(Link)
[User Picture Icon]
From:svoysredychuzih
Date:March 12th, 2013 02:09 pm (UTC)
(Link)
Thank you for the reference, but it doesn't answer my question.
(Leave a comment)
Top of Page Powered by LiveJournal.com