Results 1 to 6 of 6

Thread: searching for a trigger like "onWindowClose"

  1. #1
    Join Date
    Sep 2005
    Location
    Wiesbaden, Germany
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default searching for a trigger like "onWindowClose"

    Hey there,

    i had to create an onlineview for special data. Therefore the customer has to login to see only his own data. The login is kept in a database with several informations.

    On the mainscreen there is a logout-button, so the customer can destroy the current session and nobody can missuse his login.
    But what, if the customer only closes the window ? The session is still running and there is the possibility of missuse.
    Hence i wanted to add the logout in a function which is called, if the page windows is closed. I would need something like an "onWindowClose"-trigger.

    Does anyone has an idea how to solve that ?

    thanks in advance

    STEFAN aka whynot

  2. #2
    Join Date
    Aug 2004
    Location
    Brighton
    Posts
    1,563
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    It'd be a lot safer to simply have a short session timeout with a cookie-based session limiter.

    For example, when I'm using Natwest banking online, if I close the window, the session cookie is no longer present and I need to log in again. If I leave it inactive for 3 minutes, I need to log in again.

    cr3
    A retired member, drop me a line through my site if you'd like to find me!
    cr3ative media | read the stickies

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    I'd advise using both.
    onunload() is what you want.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I'm with cr3 on this one Twey, besides onunload() is invalid and will do nothing. If you want the double whammy of a server side cookie (what cr3 is suggesting) and a javascript approach, the correct use of onunload is:

    onunload=

    It can be used identically to the many and varied syntactical ways onload is.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Oh, I just use () to indicate a function. Sorry if I caused confusion.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  6. #6
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    There are problems with using the unload event to log a user out. There is the obvious reason: scripting is unavailable. There are less obvious reasons, too:

    • The user might not be connected to the network.
    • Script errors (your own, or introduced by advertising, perhaps) may prevent the code executing.
    • The browser might crash.
    You also need to consider that the event doesn't fire just because the browser is closed. Here's a list from Microsoft:

    • Close the current browser window.
    • Navigate to another location by entering a new address or selecting a Favorite.
    • Click the Back, Forward, Refresh, or Home button.
    • Click on an anchor that refers the browser to another Web page.
    • Invoke the anchor click method.
    • Invoke the document write method.
    • Invoke the document open method.
    • Invoke the document close method.
    • Invoke the window close method.
    • Invoke the window open method, providing the possible value _self for the window name.
    • Invoke the window navigate or NavigateAndFind method.
    • Invoke the location replace method.
    • Invoke the location reload method.
    • Specify a new value for the location href property.
    • Submit a form to the address specified in the ACTION attribute via the INPUT type=submit control, or invoke the submit method.
    It should be noted that not all of these causes will be implemented by other browsers. For instance, Opera doesn't fire the unload event at all when a tab or the browser instance is closed (something else that renders use of the event pointless).

    I would suggest just implementing a server-side timeout mechanism. If well-written, there is little risk in having idle sessions.

    Mike

Bookmarks

Posting Permissions

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