Yo there! If you are new here, you may want to subscribe to my RSS feed, or through email, for more tips on better and effective blogging!
A few days ago, I wrote about A 5-Minute Method to Redirect Your Affiliate Links . That method was only for PHP enabled servers.
However, some people had a Blogger blog and wanted to know how to do this. Since blogger doesn’t run on PHP, the above method won’t work on blogger blogs. And you also can’t use the .htaccess hack on blogger blogs.
Therefore, the only solution that I see here is to use Javscript to redirect your affiliate links. And it’s not very hard to do so, actually. It’ll not take more than 10 seconds. This method can be used for any blogging platform.
Note: For this, you have to have average knowledge of HTML and basic knowledge of Javascript.
Another IMPORTANT Note: Do all of the following in HTML mode of your blogging software.
The first and most obvious step is to create your link. You need the original affiliate link for this. As in my previous article, I’ll choose http://www.linkworth.com/?a=8168 for the sake of this tutorial.
A normal link without the javascript will look something like this:
Right? What we want to do now is to add some javascript to the link tag. For this, we use the onclick attribute, which comes in to action whenever someone clicks on the link:
Now, we add the window.location javascript object to the onclick attribute:
What the window.location does is that it sets the address in the browser’s address bar to what you’ve set and hits the ‘GO!’ button. All that in a split second ;). Don’t forget to include the semicolon at the end there. Next, add the affiliate link(the one in the href attribute) as the window.location’s value:
That’s done. NOTE: Don’t use the same type of quotation marks here. For example, if you’re using double quotation marks (”) to enclose the onclick attribute, use the single quotation marks (’) to enclose the window.location part. Or vice versa. You’ll mess things up if you use the same kind of quotes for both!
Note that the href attribute is empty now. You should remove the affiliate link from it now since you’ve already set it up in the Javascript, and its not needed anymore. However, you shouldn’t leave it completely empty, because then the whole link won’t work! Just drop a ‘#’ in there and you’ll be fine.
The next and final step is to check whether your link works or not. It should, but if it doesn’t, you’ve messed something up.
Do you have many affiliate links you would like to cloak? Do you use those links a lot in your articles? Doing each and every link using the above mentioned method is really a headache. Right?
So, what you can do is create Javascript functions for each link and place all the functions in your header file (by editing your theme’s source code) and then call those functions from inside your links. Simple and easy and time saving. Here’s what you gotta do:
1. Create separate functions for each affiliate link.
First, you have to create a separate function for each link, and enclose them within the <script></script> tags. Here’s an example:
function tla()
{
window.location = “http://www.text-link-ads.com/?ref=97644″;
}
//–>
</script>
The above were samples for two links. In reality, you can go on and on and on with the list (not recommended, though).
So, what the function does is that when it’s called, it simply sends the user to the specified address.
Step 2. Call the function.
This is the real easy part. When you’re creating your links, just make them look like this:
Notice that we replaced the original value of the onclick attribute with ‘linkworth();’. This simply means that we’re calling the linkworth function. Simple as that. If you wanted to call the tla function, the link would have looked something like this:
Now is that easy or what!
NOTE: You can’t call a function that’s not on the page of the link. For example, you can’t call a function which is located on page.php from a link which is located on home.php. Therefore, it is better to put all your function calls in the header, where it’ll be repeated every time.
And you’re DONE!
I’m not for using javascript to do all this for several reasons:
Your turn to speak up: Would you use Javascript on your blog to do anything like this?
I’d like to create a blog and liked your idea of redirecting referral links using javascript. But I can’t seem to make it work. Can you please post a working example? Tia
Rhea,
Is that firefox? Have u tried putting “#” in the href attibute instead of leaving it blank? I think it’s one of the weird things to note about FF.
Anyway, good luck with this time.
-W
great hacks. thanks anyway have to deep study and implement it.
thanks for the javascript code examples. I’ve been trying to figure this out for some time, now.
King Vanlines’s last blog post..Picking a Washington Moving Company