How can i detect that a user is trying to leave a page
Is it possible for me to know that if any user tries to leave a particular page or trying to move on to a new site? I'm trying to build a mage editor and would like to know that after finishing teh above action, it should call for a PHP function that would probably would clean up the users images from the temp files by detecting their ip address. So, can any body tell me that whether it is possible for me to do so? Kindly provide me the correct solution for the above issue. Any kind of help would be appreciated.
Re: How can i detect detect that a user is trying to leave a page
You can use Ajax script on the page that connects to the server every 30-60 seconds to say, "I'm still here". If the server doesn't hear from a particular session id, say about in 3 minutes, then you can assume that they left the page. (Better to rely on session id's than going for IP addresse).
There are Javascript events that can trigger the Ajax script on page close or navigating away but they seems to be very unreliable.
Re: How can i detect detect that a user is trying to leave a page
You can use a cookie for the user who try to open the edit, set the lifetime for the cookie on the same length as the timeout time, then you can make a check for the cookie to see if the user is the one who opened the and then allow that one to edit as long the text is locked (when it's saved the cookie is removed).
Re: How can i detect detect that a user is trying to leave a page
Hey you can go for image image trick, just follow the below code for doing it.
Quote:
unction unload() {
var cleanup = new Image();
cleanup.src = "Notify.asp";
}
<body onunload="unload()">
Hope so it might help you out.