jrcarr Posted February 22, 2006 Share Posted February 22, 2006 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 advanceJack Quote Link to comment https://forums.phpfreaks.com/topic/3522-need-to-run-a-php-script-when-window-closes-or-changes/ Share on other sites More sharing options...
ccl Posted March 9, 2006 Share Posted March 9, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/3522-need-to-run-a-php-script-when-window-closes-or-changes/#findComment-15622 Share on other sites More sharing options...
fooDigi Posted March 10, 2006 Share Posted March 10, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/3522-need-to-run-a-php-script-when-window-closes-or-changes/#findComment-16077 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.