View Full Version : Window Help
09-15-2008, 03:29 PM
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
09-15-2008, 04:04 PM
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]
09-15-2008, 06:26 PM
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.
09-15-2008, 06:36 PM
You can try to make an Ajax call to the server with onbeforeunload/onunload, other than that there is nothing you can do.
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.