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]
65 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!
Lori Ashlyafrib
September 11th, 2010 at 3:04 am
34You have shared very useful information on affiliate links. It has added a lot to my knowledge. Thanks!!
http://naturaldetoxcleanse.net/natural-body-cleanse/
Chas Driessen
September 12th, 2010 at 3:42 am
35I was doing some browsing and came across this site. I admit that this information is what I was searching for! Keep it up. Will be following your posts
nikki boy
November 10th, 2010 at 7:26 am
36thanks for this and i hope you next time give the more good info. but it’s very amazing well done.
celtrixa
faceFore
November 21st, 2010 at 10:47 pm
37ahh nice work, I was looking for something like that.
Thanks a lot for sharing it with others.
Jerry Grant
December 17th, 2010 at 6:55 am
38Very informative!! I’ll definitely use this info.
Jerry Grant
December 17th, 2010 at 6:55 am
39Very informative!! I’ll definitely use this info.
Zetaclear
Mozelle Oransky
February 2nd, 2011 at 11:23 am
40Super-Duper internet site! I am loving it!! Will come back again – taking you feeds also, Thanks.
Hello. Wonderful occupation. I did not expect this on the Wednesday. This is a good story. Thanks!
Tyler Mowbray
February 2nd, 2011 at 1:28 pm
41I keep listening to your news converse about acquiring free online grant applications so I’ve been looking about for the very best internet site to get 1. Thank you for the assist!
bowtrol
February 5th, 2011 at 11:12 am
42well thanks i can use this code
sell silver jewelry
February 24th, 2011 at 12:06 am
43http://www.creativemarineconcepts.com/2010/12/things-that-you-must-consider-before-buying-silver-jewelry/ Thanks for that awesome posting. It saved MUCH time
????
April 21st, 2011 at 8:38 pm
44Maximusokna,ru ??????????? ??????, ?????????? ? ??????? ???????? ? ??????, ???????? ????.
Lachlan
April 30th, 2011 at 11:50 am
45Do you think Google minds if we do this?
orgudantelornekleri
May 14th, 2011 at 6:57 am
46Just desire to say your article is as surprising. The clearness in your post is simply spectacular and i could assume you are an expert on this subject. Fine with your permission let me to grab your RSS feed to keep up to date with forthcoming post. Thanks a million and please carry on the rewarding work.
Shiloh Hofe
June 9th, 2011 at 10:01 pm
47Great – I should definitely pronounce, impressed with your web site. I had no trouble navigating through all the tabs and related information ended up being truly easy to do to access. I recently found what I hoped for before you know it in the least. Reasonably unusual. Is likely to appreciate it for those who add forums or something, website theme . a tones way for your customer to communicate. Excellent task.
Neuro Linguistic Programming
September 4th, 2011 at 12:59 am
48Is this the only weblog you’ve?
Papel de Parede
September 10th, 2011 at 12:44 pm
49I have learn several good stuff here. Certainly price bookmarking for revisiting. I surprise how much effort you put to make any such excellent informative site.
Lewis Armor
September 15th, 2011 at 3:42 am
50just one of the finest Affiliate Link Loveliness by 15 Days Of jQuery I stumbled onto up to now
Multiple Streams of Income
September 18th, 2011 at 5:21 am
51I wanted to post you that tiny remark to say thanks a lot over again just for the nice secrets you have featured in this case. It was really seriously open-handed with you to grant publicly just what many individuals might have offered for an ebook to generate some dough for themselves, mostly now that you might have tried it in case you desired. These secrets as well served to be a good way to fully grasp that other people online have the identical fervor much like my personal own to know the truth more regarding this matter.
Nicholas Tollerud
September 23rd, 2011 at 6:53 am
52Hello There,I think this is blog is very interesting and one of the better things I’ve read latley. But I want to say that your web site style is perfect, the articles are really great. Wonderful Job, Chow !
Tax Relief
October 13th, 2011 at 1:44 pm
53I believe that is among the most important info for me. And i’m satisfied reading your article. However wanna statement on few normal things, The site style is great, the articles is truly nice
. Good process, cheers.
????? ?????????
October 29th, 2011 at 8:21 pm
54A very useful and helpful site with great articles for everyone and for me too. I discovered your website from a link posted on a forum. I will Come here regularly because i like your site.
fungerar rogaine
November 1st, 2011 at 2:54 pm
55fungerar rogaine…
[...]r I own a similar blog to this one and I was just curious if you get a lot of nq[...]…
jocuri
November 8th, 2011 at 4:32 pm
56As someone said above, nothing!
JOCURI SLOT
November 13th, 2011 at 8:30 am
57its firs date to this blog, its nice ! keep work…..
small houses
November 21st, 2011 at 10:45 am
58How about moving into a new smaller house ?
Jorge
December 11th, 2011 at 4:28 am
59Does this code still work?
I’ve been trying to make it work, but just can’t seem to find how. I’m trying on chrome and firefox. Nothing on both.
I’m putting it inside the header. And I’m using wordpress, you think this has something to do with it not working?
Thanks for any feedback
spiderman games
December 13th, 2011 at 7:53 pm
60You have to run move, to be resourceful, there are too many Reading which have no job at all! However you hard! keep up the good work
Henry Cracraft
December 27th, 2011 at 10:46 pm
61Good post. I study something more difficult on totally different blogs everyday. It will always be stimulating to learn content material from different writers and apply a little one thing from their store. I’d want to use some with the content material on my weblog whether or not you don’t mind. Natually I’ll provide you with a link in your web blog. Thanks for sharing.
promote my website
December 30th, 2011 at 8:17 pm
62We promote your business with good advertising and SEO campaigns! Contact us: admin@adtron.net (www.adtron.net)
Ghost Bond Xl Adhesive
January 2nd, 2012 at 6:13 pm
63Spot on with this write-up, I truly think this website needs rather more consideration. I’ll probably be again to learn way more, thanks for that info.
online poker tournaments
January 4th, 2012 at 4:27 pm
64Really instructive and great structure of content material , now that’s user friendly (:.
Lectii de Poker
January 13th, 2012 at 5:07 pm
65Vrei sa inveti rapid sa joci poker? Te enerveaza atunci cand esti in avantaj si pierzi? Intra acum pe http://www.lectiidepoker.com pentru a deveni un profesionist in Poker!
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