Results 1 to 5 of 5

Thread: Handling "Exit" and "Back" events

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2001
    Posts
    8
    Hi,
    Can you please tell me how can I catch "Exit" and "Back" events on a web page?

    Thanks in advance.

  2. #2
    Fanatic Member Jerry Grant's Avatar
    Join Date
    Jul 2000
    Location
    Dorset, UK
    Posts
    810

    Unhappy Bad news!

    The biggest problem with browsers, is that you can't detect these events! IIS won't know if you have navigated to a different site, switched the PC off, or gone away from the PC for an hour!

    You have to do a work around:

    For the 'Back' event, you will have to hold a session variable, with the location of the current page. When another of your pages is entered via the back button (or shift + left arrow) then you read the session variable and act accordingly; Redirect, Alert etc.
    Alternatively, you can use the request.servervariables("HTTP_REFERER") to determine where the user navigated from, so you can do the same.

    For the 'Exit' event, you have no way of knowing. You can keep the last vistit time in a cookie, then read this on page delivery to know that a previous session was interupted, and handle as you require.

    For more on these problems see www.4guysfromrolla.com wher thy have some nifty work arounds for these problems.

    Good Luck
    Jerry Grant................tnarG yrreJ
    Website: <JG-Design></.net>
    Email: [email protected]
    Working towards a bug free world......
    (Not a Microsoft employee)

  3. #3
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    To add to what Angry jet R R said above, you can detect when a user hits the back button or closes the browser with the "onUnload" event.

    but you can't tell whether the user is going back or closing the browser.

    onUnload is also fired on refeshing the page
    Code:
    <body onUnload="alert('leaving the page')">
    
    <body>
    Mark
    -------------------

  4. #4
    Fanatic Member Jerry Grant's Avatar
    Join Date
    Jul 2000
    Location
    Dorset, UK
    Posts
    810
    Anagrams now eh Mark?
    Jerry Grant................tnarG yrreJ
    Website: <JG-Design></.net>
    Email: [email protected]
    Working towards a bug free world......
    (Not a Microsoft employee)

  5. #5
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    Duh!
    I just realised that it was your name spelt backwards after your name and not an anagram

    Full list being sent by private message
    Mark
    -------------------

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width