
Photo by Andreas Bylund
How to hide your affiliate links – part 3
August 11th, 2009 by Andreas from XavierMedia.comIn the last part we had a look at a simple javascript. Now it's time to get a little bit more advanced in the javascripting. Since most people are using the same affiliate links on several pages and also using several links on each and every page it's a must to be able to use several links per page. And it must be easy to update the links.
Javascript for multiple links per page
First we need to create a text file called linking.js (you can pretty much call it anything you like as long as it's ending in .js). This file will contain all your text links and some other code, like this:
function initArray()
{
this.length = initArray.arguments.length;
for (var i = 0; i < this.length; i++) {
this[i] = initArray.arguments[i];
}
}function Redirect(RedirectToLinkNo){
link = new initArray("http://www.xaviermedia.com/", "http://www.sampleaddress.com/", "http://blog.sampleaddress.com/" );window.location = link[RedirectToLinkNo];
}
Replace the blue links with your own affiliate links. You can add as many links as you like as long as you separate them with commas (and put "" around the URLs). Once you've added your links, just upload the file to your web account.
In any page where you're going to use your affiliate links you need to add the following code between the <HEAD></HEAD> tags:
<SCRIPT LANGUAGE="JavaScript" SRC="http://www.sampleaddress.com/linking.js"></SCRIPT>
Replace sampleaddress.com with the location of your own linking.js file.
Whenever you need to redirect a user to one of the links in linking.js just use a link like this:
<A HREF="javascript:Redirect(X);">Text</A>
X in the code indicate which one of the links to redirect the user to. If you for example want to redirect the users to www.sampleaddress.com you would replace X with 1, and to redirect users to www.xaviermedia.com you would use 0 as value for X.
The beauty with this is that you only need to change links in one file whenever you need to do updates and you're also making it little harder for visitors to figure out your affiliate codes
This is not a bullet proof solution, so in next part I will show you a little bit more secure solution done in PHP.
You may also be interested in...How to hide your affiliate links – part 1
How to hide your affiliate links – part 2
How to hide your affiliate links – part 5






