|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
|||
|
|||
|
JS to PHP Problem
I need to find another way to run a PHP script when a user leaves my website or closes their browser. The best way I've found to do this so far is with a popup using the ONUNLOAD event but I can't use a popup because of popup blockers. It must be ran when they leave and not before.
So how can I do this without a popup? Swap image somehow? Here's basically how I'm doing it now: <script> var ScriptURL = "stats.php"; function postinfo() { var poststats = ScriptURL + "?" + stats + "=" + statsvar; window.open(poststats); //call URL } </script> <body onunload="postinfo()"> etc... I've spent the last 4 days searching the net and forums for another way with no luck. Some hint about an image swap and I think that would be perfect but I'm not good with JavaScript. I would of used PHP to do it all but PHP can't do some of the stuff I need and JS can. Thanks... Abbadon |
|
#2
|
|||
|
|||
|
RE: JS to PHP Problem
Sorry not to offer you a solution here, but it seems to me that what you are trying to do violates one of the internet's most basic assumptions: that a user is free to terminate interaction with a website when he/she desires, and the only way a user usually has to do this is to close the window.
This is where you could offer the user another way to finish interacting with your website: give them a "log out securely" button, that opens up the php script, which runs and closes itself automatically. Because the user, in this case, chooses to press the button, a pop-up blocker will not be activated. However, if the user decides to close the window, there is nothing you can (or should!) do. It would be the same principle if the user's computer suddenly crashed, or if the user unplugged the computer to stop a download or a credit card purchase. You must make that allowance and do all you can to direct the user to the "log out" button instead of the little cross :-) |
|
#3
|
||||
|
||||
|
RE: JS to PHP Problem
What niko_zeta said is correct, but there is another way to get a PHP script to run than a popup window: use an image.
In your javascript, create a new Image object, then assign the source the script you want to run: Code:
<script>
var ScriptURL = "stats.php";
function postinfo() {
var img = new Image();
img.src = ScriptURL + "?" + stats + "=" + statsvar;
}
</script>
<body onunload="postinfo()">
This isn't fool-prrof, but you will probably have more luck than with pop-ups. |
|
#4
|
|||
|
|||
|
RE: JS to PHP Problem
if you threw an infinite loop in the page checking to see if connection_aborted(), then used ignore_user_abort() that might work.
but i've not played with it lately. |
|
#5
|
|||
|
|||
|
RE: JS to PHP Problem
Thanks Honcho... That works pretty good. I'ld say about 80-90 percent of the time.
Notepad... I'll look into that as a way to possibly make it a little more reliable... Thanks Abbadon |
![]() |
| Viewing: Codewalkers Forums > Other Technologies > Client Side Things > JS to PHP Problem |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|
|