бредущий по жизни (svoysredychuzih) wrote in webdev,
бредущий по жизни
svoysredychuzih
webdev

Event on closing browser window

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?
Subscribe

  • Basic HTML Document

    In this HTML 5 Tutorial we will look at a very basic HTML document. These three HTML tags are required in each HTML document.

  • Google Analytics

    At work we are having a discussion about Google Analytics referencing information by page titles and URL changes (where the node id turns into the…

  • Drupal blocks, beans, etc.

    Hi I need to create "hub pages" (pages with multiple blocks to different areas of a Drupal site) but I have limited access to what I can modify.…

  • Post a new comment

    Error

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 2 comments