Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4

Thread: Window Help

  1. #1
    New to the CF scene
    Join Date
    Sep 2008
    Posts
    8
    Thanks
    0
    Thanked 1 Time in 1 Post

    Window Help

    I am trying to figure out how to set-up a php event when the window is closed. For instance I want something to be inserted into the database when the window is closed. Can someone show me how to use the window unload event with php?

    Thanks in advance

  • #2
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    You should not be relying on the browser close event, but on PHP's On session end.

    Detecting the browser close event is nearly impossible in all cases due to may factors such as the user just turning off their computer, loosing power, browser error, BSOD, etc. None of them would fire the event. Plus there is no on browser close call, you have to rely on onbeforeunload or onunload which is called for links, post backs, refresh, and closing the window.

    If you want to try onbeforeunload or onunload, you would have to make a request with Ajax [and it might not go through]

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #3
    New to the CF scene
    Join Date
    Sep 2008
    Posts
    8
    Thanks
    0
    Thanked 1 Time in 1 Post
    Thanks for the reply. But my question to you now is how do you do an on session end event. For instance if the user just closes the page instead of logging out, I would still want it to end the session and log them out.

  • #4
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    As I said before: JavaScript can not do it.

    You can try to make an Ajax call to the server with onbeforeunload/onunload, other than that there is nothing you can do.

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]


  •  

    Posting Permissions

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