Jump to content


Photo

Run script on page leave


  • Please log in to reply
3 replies to this topic

#1 TitusRevised

TitusRevised
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 05 July 2006 - 05:38 PM

Is there any php function that will run only when the page is left.
I want a table in my mysql database to erase specific rows once the user leaves the page.
Is this possible?
Help is much appreciated.

#2 Koobi

Koobi
  • Staff Alumni
  • Advanced Member
  • 419 posts
  • LocationColombo, Sri Lanka | South Asia

Posted 05 July 2006 - 05:40 PM

this would be a client side trigger so you would have to use JavaScript.

i would not use this approach though. many things can go wrong...the user could close the browser or kill the browser process on his OS, the browser could crash, the ISP could drop his connection. too many uncertainties in my...but who knows, maybe someone knows something i don't and this is possible but as far as i know, i don't think this is a good solution.

#3 TitusRevised

TitusRevised
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 05 July 2006 - 05:46 PM

this would be a client side trigger so you would have to use JavaScript.

i would not use this approach though. many things can go wrong...the user could close the browser or kill the browser process on his OS, the browser could crash, the ISP could drop his connection. too many uncertainties in my...but who knows, maybe someone knows something i don't and this is possible but as far as i know, i don't think this is a good solution.

Well, the the page information wil be saved in a session so if they close browser then no need to execute a script. But if they navigate away from that single page, then I need a script to run first then send them to where they want to go. If it has to be done in JavaScript, can anyone direct me to help?

#4 Koobi

Koobi
  • Staff Alumni
  • Advanced Member
  • 419 posts
  • LocationColombo, Sri Lanka | South Asia

Posted 05 July 2006 - 05:52 PM

oh ok then you can do something here. sorry i misunderstood your first post.

in this case i think the safest thing to do would be to have an intermediate page that redirects the user to their requested page.

so your user wants to go from one.php to two.php and the moment he leaves one.php, you want the script to execute.

the link he clicks would take him to intermediate.php and this script's job is to redirect the user to the requested page based on certain conditions.
these conditions could be the execution of your query for example.
so you would have a session variable that tracks URL's and the moment this changes, you would execute this query of yours and then redirect him from this page (i.e. intermediate.php) to two.php


hope that made sense.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users