Welcome to WebmasterWorld Guest from 54.204.162.36

Forum Moderators: incrediBILL

Script working with IE6.0 but not with FF2.0

Browser compatibility

   
10:19 pm on Feb 16, 2008 (gmt 0)

5+ Year Member



I wonder if somebody can help me with this script. It is meant to track outgoing links. It works without any problem with IE but not with FF.

<script>
function track(link)
{
new Image().src = 'http://myserverurl.com/tracking/track_click1.php?id=1&href='+ location.href;
}
</script>
<a href="http://www.linktobetracked.com" onclick="track(this)">Link</a>

Can somebody provide any kind of hint?

Thanks

9:36 am on Feb 19, 2008 (gmt 0)

WebmasterWorld Senior Member blobfisk is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Have you tried:


<script>
function track(link)
{
[b]link[/b].src = 'http://myserverurl.com/tracking/track_click1.php?id=1&href='+ location.href;
}
</script>
<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)

5+ Year Member



BlobFisk:
this/link is not an image.

yd0802:
The problem is that FF has not the time to load the image before loading the page pointed by the <a> link.

alternative solutions:
- 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)

5+ Year Member



Hello Achernar,

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)

5+ Year Member



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:

<script>
function track(link)
{
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;
setTimeout(function(){location=link.href},0)
return false;
}
</script>
<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)

5+ Year Member



thanks!
 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month