Page 1 of 1

onUnLoad

Posted: Thu Apr 07, 2005 2:21 am
by s.dot
would it be possible to execute a MySQL query using the onUnLoad javascript event handler?

for example

Code: Select all

<body onUnLoad=&quote;<? // mysql query // ?>&quote;>
The reason I ask is because if someone navigates away from this page or closes the browser, I want to remove their name from my database. I do not want it to be a time thing.. where like it deletes them if they have been inactive for so long. But rather a true indication of them being on the page or not.

Posted: Thu Apr 07, 2005 2:40 am
by CoderGoblin
Remember client side things do not normally affect server side things so unfortunately it is not as simple as that :cry:. What you need to do is relocate to a "logout" page using javascript. You have two problems

1) Ensuring the unload of the page still retains the user command (e.g the user still goes to the page requested. A popup may be of use here but you would need to ensure popup blockers to not prevent activation.

2) What happens if users do not have javascript active.

These two reasons are the main reasons why people tend to time out as well as a link to logout.