Re: Distinguishing between a mouse click and a refresh?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Oooh... now that I think about it, it doesn't work. Sorry =(

On 12/4/06, Paul Novitski <paul@xxxxxxxxxxxxxxxxxxx> wrote:
Hi Casey,

Yes, I can see that your javascript function adds a random number to
the href of a clicked link, but how does that help PHP distinguish
between a page loaded that way and that same page reloaded with the
refresh button in the browser's chrome?  That was the OP's problem.

Regards,

Paul



At 12/4/2006 09:30 PM, you wrote:
><script>
>// NOT TESTED
>document.onclick = function(e) {
>  var targ;
>if (!e) var e = window.event;
>if (e.target) targ = e.target;
>else if (e.srcElement) targ = e.srcElement;
>if (targ.nodeType == 3) // defeat Safari bug
>targ = targ.parentNode;
>query = Math.floor(Math.random()*10000);
>if (undefined !== targ.href)
>targ.href=targ.href.indexOf("?")!=-1?targ.href+"&"+query:targ.href+"?"+query;
>}
></script>
>
>On 12/4/06, Paul Novitski <paul@xxxxxxxxxxxxxxxxxxx> wrote:
>>At 12/4/2006 01:08 PM, Jay Blanchard wrote:
>> >[snip]
>> >Is there any way for PHP to know whether it is being called due to a
>> >browser refresh versus a mouse click?  I think the answer is no but I
>> >just want to be sure.  Thanks.
>> >[/snip]
>> >
>> >Not unless you specifically capture and send a JavaScript onClick event.
>> >A mouse click typically takes you somewhere else, so if you are using
>> >for a page refresh you could capture and send a JavaScript variable to
>> >the PHP script.
>>
>>
>>The tricky bit would be distinguishing between a page loaded with a
>>mouse-click and a subsequent reload of that same page, as they would
>>share the same querystring.  One way would be to use javascript to
>>supply the current absolute time in the querystring at the moment of
>>click (you could do the same sort of thing with submit using a hidden
>>field or a querystring appended to the form action), then PHP could
>>compare that time with its own current time to see if the querystring
>>represented a current or old rendering.
>>
>>That would fail with javascript disabled, of course.
>>
>>A server-side-only solution could pre-populate all the links on the
>>site that point to this page with a special querystring.  When the
>>script/page is invoked with that querystring, PHP does the necessary
>>processing and then redirects to itself (the same page) but without
>>the special querystring.  Therefore reloading the page that's
>>downloaded to the client won't reinvoke the post-click process.
>>
>>Regards,
>>Paul
>>
>>--
>>PHP General Mailing List (http://www.php.net/)
>>To unsubscribe, visit: http://www.php.net/unsub.php
>>



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux