How to identify opening a new tab event

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Nithu25
    New Member
    • Nov 2007
    • 15

    How to identify opening a new tab event

    Hi All,

    I am facing one issue related to session.

    Suppose the user closes the window without Logging out, in firefox and in Safari (Mac OS) , the user will be automatically logged in,when they open a new window or a new tab.

    Is there any way to identify the event of closing the window or tab, opening a new window or tab using javascript, evenif its opened using mouse or keyboard?

    If any one know the solution, kindly help me.
    Thanks in advance.
    Last edited by Nithu25; Apr 7 '08, 07:20 AM. Reason: Mistake in title
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Rather than restricting the user opening new windows or tabs, just use a session timeout - after a period of inactivity, the user is automatically logged out. This saves the hassle of trying to detect events and other hacks.

    Comment

    • abhishekbrave
      New Member
      • Dec 2007
      • 79

      #3
      Originally posted by acoder
      Rather than restricting the user opening new windows or tabs, just use a session timeout - after a period of inactivity, the user is automatically logged out. This saves the hassle of trying to detect events and other hacks.
      Try to kill the session in the logout page.

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        Originally posted by abhishekbrave
        Try to kill the session in the logout page.
        That's an obvious solution, but did you read the OP's post? The problem is when users close the tab/window without logging out.

        Comment

        • pronerd
          Recognized Expert Contributor
          • Nov 2006
          • 392

          #5
          Originally posted by Nithu25
          Suppose the user closes the window without Logging out, in firefox and in Safari (Mac OS) , the user will be automatically logged in,when they open a new window or a new tab.
          Some additional thought maybe required for this. The condition described should not be a problem.

          First off you may not want to log users out just because they open a link on your page in a new tab. With tabbed browsers now being so common this probably happens often and would cause a lot of confusion for your users if they where logged out each time they selected "Open in a new tab"

          Also if the user completely closes their browser then and then reopens it a new session ID should be getting generated for them. This is not entirely true with some new auto session recovering features. If they do still have the same session ID, and that is still valid (i.e. not timed out) then there should not be a problem.

          If there session has timed out they should be getting forwarded to a login page.




          Originally posted by Nithu25
          Is there any way to identify the event of closing the window or tab, opening a new window or tab using javascript, evenif its opened using mouse or keyboard?
          You could trigger a request to the server to log the user out on the onunload event for the body tag. This is not really that reliable though.

          Comment

          • Nithu25
            New Member
            • Nov 2007
            • 15

            #6
            But if i am using 'onunload' it will be affected in all the events fired in that page, which i don't want.I want to catch the event of closing window only, so that i can call logout on firing that event.

            Comment

            • Nithu25
              New Member
              • Nov 2007
              • 15

              #7
              And it should work in all the browsers- IE,Firefox and Safari (Mac OS).

              Comment

              • acoder
                Recognized Expert MVP
                • Nov 2006
                • 16032

                #8
                Originally posted by Nithu25
                But if i am using 'onunload' it will be affected in all the events fired in that page, which i don't want.I want to catch the event of closing window only, so that i can call logout on firing that event.
                I don't think you can reliably catch the window close event.

                What if the user accidentally closes the window? They'd be pretty miffed if they had to login again. What's wrong with a session timeout?

                Comment

                Working...