Re: capture 'browser closed'

Discussion in 'ASP .Net' started by Marina, Jun 24, 2004.

  1. Marina

    Marina Guest

    There is the client side onbeforeunload and onunload event. However, the
    problem with those, is that they fire whenever the page is unloaded - even
    if it's for a postback or going to a different page. So you basically have
    to keep track of all user actions, to make sure your code is firing only
    when necessary.
    You would have to put some code in the event handler to do a server side
    call to do the logout.

    "Carlo Marchesoni" <> wrote in
    message news:...
    > As far as I understand this is something that a lot of poeple tries to do,

    but it does not seem to be easy: is it possible to catch the event of
    closing the browser ? The enduser is logged into my application and I would
    like to do a clean logout. This works fine as long as the enduser hits the
    'Logout' button, but most of the time he just closes the browser window
    itself.
    Marina, Jun 24, 2004
    #1
    1. Advertising

  2. here is a traditional approach, its not compliance with
    postbacks/links but you can customize it..
    http://p2p.wrox.com/archive/asp_webserver/2003-01/2.asp
    http://www.codeave.com/javascript/code.asp?u_log=7014


    controlpanel.aspx:
    ------------
    <script language="JavaScript">
    <!--
    function UnLoad() {
    window.open("logoutuser.aspx");
    }

    // -->
    </script>
    <body onUnload='UnLoad()'>

    Close me to invalidate the session

    </body>

    logoutuser.aspx:
    ---------
    <% Session.abandon () %>
    <script language="JavaScript">
    function Load() {
    self.close();
    }
    </script>
    <body onload='Load()'>
    session gone...
    </body>

    --
    Hope this helps,
    Zeeshan Mustafa, MCSD


    "Marina" <> wrote in message
    news:%23Jq$...
    > There is the client side onbeforeunload and onunload event. However, the
    > problem with those, is that they fire whenever the page is unloaded - even
    > if it's for a postback or going to a different page. So you basically have
    > to keep track of all user actions, to make sure your code is firing only
    > when necessary.
    > You would have to put some code in the event handler to do a server side
    > call to do the logout.
    >
    > "Carlo Marchesoni" <> wrote in
    > message news:...
    > > As far as I understand this is something that a lot of poeple tries to

    do,
    > but it does not seem to be easy: is it possible to catch the event of
    > closing the browser ? The enduser is logged into my application and I

    would
    > like to do a clean logout. This works fine as long as the enduser hits the
    > 'Logout' button, but most of the time he just closes the browser window
    > itself.
    >
    >
    M. Zeeshan Mustafa, Jun 24, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. mike
    Replies:
    0
    Views:
    683
  2. hb
    Replies:
    6
    Views:
    739
  3. Nikhil Patel

    saving data when browser is closed

    Nikhil Patel, Aug 26, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    571
    Weston Weems
    Aug 26, 2004
  4. Max
    Replies:
    7
    Views:
    9,104
  5. Matt Kruse
    Replies:
    5
    Views:
    309
    Richard Cornford
    Sep 9, 2003
Loading...

Share This Page