Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi All,
Is there anyway to save users' information in a database when a user closes x button form the browser.
I have a logout button that takes care it only if they click log out button. But if the click x button in browser how do I save all the information. I am using php.
Any help will be geatly appreciated.Thank you.

I believe that it will take a lot of work. I did a google on "window close event" and found the following page: http://www.dotnetjunkies.com/WebLog...
Basically it says there is no "window close event" but gives another suggestion.
Also, you have the problem that catching this event (pushing the X button) is handled by javascript, which is on the client (the user's PC) but the saving info to the database needs to be done on the server. You'll have to make the javascript that is called do a 'submit' to get the info to the server so that it can be saved.
But I guess that you understand that part, since you have a logout button. So the key is to catching the 'beforeunload' event mentioned. Note that this still doesn't cover all possibilities.

Are you talking about a web application? If so, you'll have to do your updating in the session close (if you're using ASP or JSP), which will happen around half an hour after the last page was pulled up (depending on the server settings). Obviously, any data not submitted before the browser is closed will not be saved.
You can try the onUnload JavaScript event, but there's no guarantee that the event will fire; JS could be disabled, or a security setting could block it.

Right. It's not clear where the users are entering this information. Web-based application? Access Database? SQL? Some other?
Life's more painless for the brainless.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |