Jump to content

Archived

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

jrcarr

Need to run a PHP script when window closes or changes

Recommended Posts

Hello,
I've gotten pretty good a programming in PHP, however, my Javascript leaves a lot to be desired.

I'm looking for a way to run a small PHP function with a just a mysql_query if someone closes the browser window or leaves the page and navigates to another page. I'm assuming I need to use onunload() in the body tag, but I don't know if I can use it to call a PHP function directly or if I need to create a Javascript function, that calls a php function. If this is possible, could someone show me some basic code to achieve this. Thanks in advance

Jack

Share this post


Link to post
Share on other sites
php runs on the server so you can not use a php function in the browser. You have to submit the page if you want to use php.

Share this post


Link to post
Share on other sites
to elaborate on eors comment..

the server parses the php code first, which sends the results to the client, which the clients browser then parses the javascript. but there are a few 'possible' solutions to your problem, depending on your needs.

how about... calling a new window, maybe a popup, that contains the code needed to run? and of course it could close itself, minimizing user interaction.

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.