homepage Welcome to WebmasterWorld Guest from 54.205.168.88
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Browsers / Firefox Browser Usage and Support
Forum Library, Charter, Moderators: incrediBILL

Firefox Browser Usage and Support Forum

    
Script working with IE6.0 but not with FF2.0
Browser compatibility
yd0802




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

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

 

BlobFisk




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

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]

Achernar




msg:3578892
 4:34 pm on Feb 19, 2008 (gmt 0)

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()

yd0802




msg:3581530
 8:29 pm on Feb 21, 2008 (gmt 0)

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.

Achernar




msg:3582032
 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:
<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]

yd0802




msg:3582091
 3:16 pm on Feb 22, 2008 (gmt 0)

thanks!

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Browsers / Firefox Browser Usage and Support
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved