Jump to content

Need to run a PHP script when window closes or changes


jrcarr

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

  • 2 weeks later...
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.