hassank1 Posted October 22, 2008 Share Posted October 22, 2008 I want when the user close the browser window to execute some php lines.. how can I do that.. ? thx. Link to comment https://forums.phpfreaks.com/topic/129656-on-window-close-execute-php-statement/ Share on other sites More sharing options...
prexep Posted October 22, 2008 Share Posted October 22, 2008 PHP can't execute code after a brower is closed or clicked to exit. JS can. Link to comment https://forums.phpfreaks.com/topic/129656-on-window-close-execute-php-statement/#findComment-672242 Share on other sites More sharing options...
DarkWater Posted October 22, 2008 Share Posted October 22, 2008 You can't. Why? P.S: For anyone who says 'Ajax', that won't even work. Link to comment https://forums.phpfreaks.com/topic/129656-on-window-close-execute-php-statement/#findComment-672244 Share on other sites More sharing options...
hassank1 Posted October 22, 2008 Author Share Posted October 22, 2008 hmm can't I use javascript and inside the event handler include php ex: onwindowclose() { //php here using document.write or something } Link to comment https://forums.phpfreaks.com/topic/129656-on-window-close-execute-php-statement/#findComment-672247 Share on other sites More sharing options...
DarkWater Posted October 22, 2008 Share Posted October 22, 2008 No. Link to comment https://forums.phpfreaks.com/topic/129656-on-window-close-execute-php-statement/#findComment-672249 Share on other sites More sharing options...
Barand Posted October 23, 2008 Share Posted October 23, 2008 P.S: For anyone who says 'Ajax', that won't even work. Can you elaborate on why not? Link to comment https://forums.phpfreaks.com/topic/129656-on-window-close-execute-php-statement/#findComment-672351 Share on other sites More sharing options...
CroNiX Posted October 23, 2008 Share Posted October 23, 2008 it seems like you could... <script> window.unload=closeFunction(); function closeFunction(){ //AJAX request to trigger PHP script //possibly add something to a database that a cronjob will check periodically } </script> Link to comment https://forums.phpfreaks.com/topic/129656-on-window-close-execute-php-statement/#findComment-672360 Share on other sites More sharing options...
PFMaBiSmAd Posted October 23, 2008 Share Posted October 23, 2008 On a more basic level, hassank1, what are you trying to accomplish? A long time ago, I attempted to use an onUnload event to send a http request (not using the XMLHttpRequest object) and I was able to get IE to send it but not FF. Has anyone recently attempted actual code using AJAX to send a http request due to an onUnload event? If it works, I'm going to guess it is going to be browser specific. Link to comment https://forums.phpfreaks.com/topic/129656-on-window-close-execute-php-statement/#findComment-672428 Share on other sites More sharing options...
Lodius2000 Posted October 23, 2008 Share Posted October 23, 2008 you could make a submit button that runs your php and then js closes the window Link to comment https://forums.phpfreaks.com/topic/129656-on-window-close-execute-php-statement/#findComment-672431 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.