Detecting leave page

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Meganutter
    New Member
    • Mar 2009
    • 47

    Detecting leave page

    Hello,

    im making a forum and stumbled upon the following problem.
    i want to detect when a user leaves the page, when the user leaves the page i want to null a Session variable.
    I am doing this in the Admin control panel, this will have an extra login which will create an AdminAuth Session variable. when the user navigates off the page it will remove that variable. The page uses Webcontrols to display various aspects thus will be refreshed.

    any help will be appreciated

    Greetz
    - Mega
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Hi Mega,

    This is going to involve using JavaScript. The onbeforeunload JavaScript event is executed before the page is unloaded.

    This event occurs if the user is leaving the page, closing the browser, or the page is preforming a PostBack to the server. So, this means that you're going to have to write a bit of JavaScript that registers all of the controls on the page in order to determine whether or not the page is posting back (since you don't want to log out the user at that point). By "registerin g" all of the controls, I mean you have to ensure that they set some variable to true if the page is unloading because of a PostBack.

    Read over the onbeforeunload event (note that it's not supported in opera), and then check out this post.


    Cheers!

    -Frinny

    Comment

    • Meganutter
      New Member
      • Mar 2009
      • 47

      #3
      hmmm, the PostBack gave me an idea.
      to check for the variable on initial load, and then destroy it. skipping this check on postback.
      if that doesnt work i might have to resort to JavaScript (which i dont really have any knowledge of)

      Thanks for the reply

      Comment

      Working...