Jump to content

Archived

This topic is now archived and is closed to further replies.

TitusRevised

Run script on page leave

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
[quote author=Koobi link=topic=99548.msg392058#msg392058 date=1152121255]
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.
[/quote]
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.