Today’s tutorial is a quickie. I want to tackle something easy early on in the “15 Days” so that someone new to javascript can sink their teeth into a real world example without getting bogged down in code.
The fact that I find myself desperately short on time today with deadlines looming certainly sealed the decision.
We’re going to create a quick little snippet of code using jQuery that will convert and camouflage all of our affiliate links on a page.
Some affiliate marketers believe that there’s a segment of their audience that is savvy enough to spot an affiliate link and will avoid clicking through the link - typing the url directly into the browser to “cheat” the affiliate marketer out of their commission (assuming a purchase is made).
There are lots of ways affiliate marketers have devised to camouflage their links or to make it very difficult for someone to avoid clicking through their link. Some of these methods involve .htaccess and server side code.
But for the purpose of this tutorial I’m going to focus on some “old school” javascript:
<a onMouseOver='window.status="http://www.merchant-url-here.com"; return true;' onMouseOut='window.status="Done"; return true;' href="http://www.affiliate-url-here.com" target="_blank">Link Text Here</a>
This code is designed to show the generic url in the status bar of the browser when a website visitor hovers their cursor over the link. So instead of seeing www.website.com?aff=123 they see www.website.com
You’re an active affiliate marketer with multiple links on multiple pages and you’re adding content at a frantic pace. Writing all this code gets tiresome. And putting javascript into each affiliate link will make updating your websites a nightmare if at some point down the road you decide to change something about the code and the way the links are displayed.
First step:
We want the javascript to camouflage our links as soon as possible so we start with this:
<script src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
//code goes here
});
</script>
As soon as the DOM (Document Object Model) is ready, the code inside of the ready(function(){}) will start.
Next
We’re going to give all of our affiliate links a class name and a title. The class name will help jQuery scan the page and find all of the links we want changed, leaving all other links untouched.
The title will serve two purposes: when the cursor hovers over the link, a tiny tootip-like box will appear with the www.website.com url displayed and the same url information will display in the bottom of the browser window (Internet Explorer only).
<p><a href="http://www.affsite.com?id=123" title="http://www.affsite.com" class="affLink">Super Duper Product</a></p>
Tell jQuery to Find Links With class=”affLink”
$('a.affLink')
Add A Mouseover Event
$('a.affLink').mouseover(function(){window.status=this.title;return true;})
Simply put, this says “Find all links with class name affLink and onMouseover change the status of the browser (where link information is shown) to whatever you find in the title of the link.”
This does not work in FireFox (made fav browser) but it works for Internet Explorer (what most of the world uses - unfortunately). And in FireFox it just displays ‘Done’, or more accurately, moving the cursor over the link doesn’t have any effect on the status bar of the browser. I have not tested this in other browsers.
Home Stretch - Mouseout
jQuery lets us “chain” methods together like so:
$('a.affLink').mouseover(function(){window.status=this.title;return true;})
.mouseout(function(){window.status='Done';return true;});
This last bit of code tells jQuery to change the status bar of the browser back to ‘Done’ when the cursor is no longer hovering over the link.
If chaining mouseover and mouseout is a little more than you want to tackle as you get used to jQuery then there’s nothing wrong with writing your code like so:
$('a.affLink').mouseover(function(){window.status=this.title;return true;});
$('a.affLink').mouseout(function(){window.status='Done';return true;});
It’s up to you.
Put It All Together
<script src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('a.affLink').mouseover(function(){window.status=this.title;return true;})
.mouseout(function(){window.status='Done';return true;});
});
</script>
Some of you may be thinking this “Day” to be a bit simplistic. Others may have a difficult time seeing the point of the tutorial because you’re not an affiliate marketer.
In “Days” to come you’ll see me tackle issues that get more involved and apply to almost anyone with a website - whether you monetize your traffic or not.
[tags]affiliate marketing, affiliate links, DOM, javascript, jQuery[/tags]
33 Responses
Max
June 11th, 2006 at 6:48 pm
1I’m a newbie to jquery but I just implemented this tutorial into some of my pages and I LOVE IT.
So much easier, faster & better. One issue though, when I refresh the page the affiliate ids are revealed

Jack
June 11th, 2006 at 8:47 pm
2I haven’t seen that myself, but what you could try would be to put the javascript code at the end of your html.
Max
June 12th, 2006 at 7:42 pm
3Putting at the bottom did the trick.
Thx
Casey
October 8th, 2006 at 9:38 am
4You can allow firefox to let javascript update the status…
http://kb.mozillazine.org/Firefox_:_FAQs_:_About:config_Entries
search for (2nd location):
disable_window_status_change
Roso
October 30th, 2006 at 1:06 pm
5It is weird, in IE(6) this takes effect on some links and is still showing the url on other.
links for 2007-03-04 « thund3rbox
March 3rd, 2007 at 8:26 pm
6[...] Affiliate Link Loveliness - Javascript Tutorials - 15 Days Of jQuery This entry was written by thund3rbox and posted on March 4, 2007 at 12:22 am and filed under . Bookmark the permalink. Follow any comments here with the RSS feed for this post. Post a comment or leave a trackback: Trackback URL. « they quietly took the body away [...]
Bhavesh Goswmai
April 19th, 2007 at 5:52 am
7Hi,
Interesting topic to discuss. I think javascript coding for an affiliate is more effective from SEO point of view. I personally visit many websites through search engine and found one website http://www.theispguide.com that used many affiliate links. Also i found one good tool to check outbound links and found that they have many outbound links that may cause problem in eye of search engine. I personally recommend to webmaster to keep balance betn website inbound and outbound links.
As we all know java script coding is tough for search engine to crawl and for affiliate link its is good idea to use javascript. Search engine will not count it as outbound link and may help you in improve your ranking in Search Engine.
Take Care,
Bhavesh Goswami.
fumobofukobutu
May 28th, 2007 at 7:52 am
8Anybody can observe the Sabbath, but making it holy surely takes the rest of the week
V'leOnica Roberts
June 27th, 2007 at 8:03 pm
9I am looking for a way to track the number of people sent from my site to another site via a link. Another words, how many people who were at my site clicked on the link that then took them to a different site.
livingston
September 20th, 2007 at 7:42 am
10Great stuff. This will be very useful and keep my code clean and fresh. I just love jQuery
'ILLEGAL
April 12th, 2008 at 5:31 pm
11None…
None…
Paperboy
April 26th, 2008 at 5:37 pm
12Yeah this is good stuff! But - I don’t want the tooltip that comes with the title attr to show and I don’t want to add a class to my aff links so this is what I, as a jQuery newbie, think I’ll do:
$('a[href]:not([href*=#],[href^=/])’).attr(’rel’, function() {
return this.title;
});
$(’a[href]:not([href*=#],[href^=/])’).mouseover(function() {
$(this).attr(’title’,”);
window.status=this.rel;
return true;
})
.mouseout(function() {
window.status=’Done’;
return true;
});
Internal link to Some Section
Anchor link
Some Afflink
Aleksey
May 30th, 2008 at 8:55 am
13Paperboy, something wrong with last message or I don’t understand something… (
I cannot disassemble, that you have written. Please, write once again
luke lu
June 24th, 2008 at 10:37 am
14what a wast of time ,,,, it does not work at all……(both in firefox IE7)
GodsDead
September 16th, 2008 at 1:48 pm
15Ausom, now how would i use ajax to record the hits out?
Gerardo Lima
September 23rd, 2008 at 9:36 am
16i’m still new to jquery, but by now i’ finding it GREAT! but i still don’t get why jquery enthusiasts cherrish so much chainning annoninous functions, since it rappidly causes readability hell.
Lisa
January 4th, 2009 at 10:02 pm
17Looks great! Thanks for supplying us with an alternative for our affiliate links. I’ve been looking for a way to make things stand out differently but hadn’t been able to achieve the effect I was going for until now. Great!
Praveen
January 21st, 2009 at 5:08 am
18yeh……
It wont work in firefox….
I am using this
Click here
how is it…
but it will open yahoo site when javascript is disabled
ACXAT
March 25th, 2009 at 2:28 pm
19Find the files you are looking for at the most comprehensive source for free-to-try files downloads on the Web
komik
April 18th, 2009 at 3:24 pm
20thank you
?a????o??a
May 22nd, 2009 at 11:05 pm
21?????????? ?? ??????, ? ??? ????
? ??????? ??????????, ??????????! 
WebWorker
June 12th, 2009 at 7:48 pm
22Thank you for this.. But because of the fact that Firefox doesn’t mask the URL my solution instead was to just override the click event.
e.g. $(”a”).click(function(){ window.location = ‘http://domain.com?myaffid=1′; return false; });
sc
June 18th, 2009 at 4:22 pm
23if you don’t want to get the title tooltip you can use $(’a.affLink’).mouseover(function(){window.status=$(this).text();return true;})
and it will return whatever is between the tag
Bo????????
July 1st, 2009 at 6:57 pm
24?? ??? ???? ???????? ? ????? ?????? ?????. ????????? ,??? ?? ???
???????????. ????? ??? ????? ?????? ???? 
??????????
July 8th, 2009 at 6:39 pm
25?????-?? ???????? ???????
pligg.com
July 18th, 2009 at 2:25 am
26Affiliate Link Loveliness…
We’re going to create a quick little snippet of code using jQuery that will convert and camouflage all of our affiliate links on a page….
????????
July 21st, 2009 at 5:44 pm
27??????? ? ???????? ?????? ????. ?????? ? ?? ?????????. ????????? ?? ????. ??????????? ?????! ??????? ???????! ? ???? ? ???????? ???? ????????!
???a
August 18th, 2009 at 6:49 am
28????????? ????????. ????? ?? ???? ?????, ?????????? ?????????? ??? ??????????? ??????.
Bepca??E
August 21st, 2009 at 10:01 pm
29??????????? ??????. ???? ????? ???????????. ??? ???? ??????? ?? ????????? ????.
scs
April 22nd, 2010 at 2:27 am
30It doesn’t work on FireFox….why?
15 dni z jQuery | Nieobiektywny Blog
May 8th, 2010 at 2:05 pm
31[...] dzie? 3 – Affiliate Link Loveliness [...]
yesterday305
June 10th, 2010 at 4:41 am
32Yes. It works good in IE. But in IE, it’s not effect. Why?
yesterday305
June 10th, 2010 at 4:42 am
33Sorry, I mean, in Firefox , it does work!
RSS feed for comments on this post · TrackBack URI
Leave a reply
Categories
Archives
Links
15 Days Of jQuery is proudly powered by WordPress - BloggingPro theme by: Design Disease