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. Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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 } Quote Link to comment Share on other sites More sharing options...
DarkWater Posted October 22, 2008 Share Posted October 22, 2008 No. Quote Link to comment 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? Quote Link to comment 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> Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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.