| 9:36 am on Feb 19, 2008 (gmt 0)|
Have you tried:
[b]link[/b].src = 'http://myserverurl.com/tracking/track_click1.php?id=1&href='+ location.href;
<a href="http://www.linktobetracked.com" onclick="track(this)">Link</a>
[edited by: BlobFisk at 9:36 am (utc) on Feb. 19, 2008]
| 4:34 pm on Feb 19, 2008 (gmt 0)|
this/link is not an image.
The problem is that FF has not the time to load the image before loading the page pointed by the <a> link.
- link to a redirect page on your domain: /redir.php?u=http://www.linktobetracked.com
- pause a quarter, or half a second before exiting from track()
| 8:29 pm on Feb 21, 2008 (gmt 0)|
I cannot use redirect because I am using a free host and that is against the TOS.
However, I found the solution. As you mentioned, it appears indeed that FF has not the time to load the image. However, adding target="_blank" in the <a> gives a little extra time ... just enough for the onclick to be successfull.
Although it opens a new windows for the link (no so elegant), it does solve my problem.
Thanks for all support.
| 1:49 pm on Feb 22, 2008 (gmt 0)|
It doesn't give extra time, it just opens a new window. So FF as all the time it needs to fetch the image.
Here is a working solution:
new Image().src = 'http://myserverurl.com/tracking/track_click1.php?id=1&href='+ location.href;
if (link.target && (link.target!="_top")&&(link.target!="_self")&&(link.target!="_parent")) return true;
<a href="http://www.linktobetracked.com" onclick="return track(this);" target="_parent">Link</a>
What does it do ?
If there is a "target" that opens a new window (either target="_blank", or a named window target="A_name"), the script allows the normal "click on a link" processus to proceed.
If there is no target, or one that doesn't open a new window, il stops the normal clicking processus by returning "false". It sets a timer to do this instead.
Note: waiting for "0" second means that the timeout will start immediately after the current script as ended. 0 is enough to allow FF to request the image. Even if it has not the time to complete the load, your sever log will show the request.
I've not refined the code to open the link correctly when "target" is either "_top" and "_parent".
[edited by: Achernar at 2:07 pm (utc) on Feb. 22, 2008]
| 3:16 pm on Feb 22, 2008 (gmt 0)|