How to hide affiliate links with JavaScript

While some people have a dilemma how to label their affiliate links, I’ve got an idea to hide them. Not in the traditional sense of the word. Sometimes I just want to make my affiliate links look like the ’standard’ ones, without ugly affiliate code. Why? For the reason unknown people (especially my natives) have a habit to copy address of affiliate link, paste it to browser’s address bar, and then they are cutting off our lovely affiliate codes. It seems that something is wrong. And, hell yeah, I’m gonna fix it!

The goal is clear. I just want to make an affiliate link that will show address without dirty affiliate code on browser’s status bar. I’ve tried a few JavaScript solutions. Window.status has not worked correctly. OnClick, too. Of course you can put it into Flash button, for example, but wait. It has to look like a basic html text link. Man. Finally I found a lucky one.

Here is an example. There is an exemplary smart text link to Yahoo. Take a closer look at it. It looks like it directs straight to Yahoo, doesn’t it? But if you click on it, you will go to Google. ;)

<a href="http://www.yahoo.com" onclick="parent.location.href='http://www.google.com'; return event.returnValue=false">Yahoo</a>

Hell yeah, it works. User thinks that he clicks regular link, but if he clicks it, he will be redirected to address with affiliate code. Of course if someone has JavaScript turned off, he will go to basic address from href, but let’s say it - everyone has turned it on. Except Google Bot. ;)

UPDATE:
This post needs some information about disadvantages of exemplary link with a little JavaScript addition. First one, if user opens that link in new tab (window?) browser will not follow address from JavaScript code. Secondly, that code doesn’t work in RSS readers, so do not use it in blog posts, news on your sites, etc. It might be cool only for your sidebar, or a site specifically prepared for affiliate marketing, you know…

UPDATE 2:
Could anybody test this one in IE7? :arrow: Yahoo

UPDATE 3:
Alright folks, Steve reported that code works properly even in Internet Explorer 7.

Tags: ,

Commented 25 times

  1. Andrea Micheloni says:

    Many people claimed it was actually a security issue (and I’m sure it should be removed): think about a link to ebay (and the status bar says http://www.ebay.com) that redirects when clicked to http://www.ebay.com.app.com/user/login or some other (smarter) URL made for phishing…

  2. Jon Lee says:

    That’s pretty clever :) reminds me of the old days where you could put anything into the IE status bar!

  3. Florchakh says:

    Andrea, maybe not for phishing. Let’s say you can use that smart trick in order to make sport of somebody. By preparing a link to delete an account on some service, for example.

    Jon, you are right. Sadly, we are not able to play with status bar of Firefox :D

  4. Azmeen says:

    Or why not just URL redirection services to hide them?

    Something like http://blings.info/ can do this for you.

  5. Florchakh says:

    Why?!

    Just because we don’t need to create an alias, but a link that has ‘inconspicuous’ look like, dude.

  6. Heather says:

    I love this, thanks. This is also a smart way to receive value from your links and avoid URL canonicalization. You rock.

  7. Erwin says:

    Love this!

    Reminds me of “Invisible Man” which I read about in my school days.

  8. Ben says:

    The obvious solution is to have a very simple redirection script on your website.

    You link to yoursite.com/goto/xxx which in turn redirects to wherever.

  9. mark rushworth says:

    err shouldn’t that have been…

    <a href="http://www.yahoo.com" onclick="top.location.href='http://www.google.com'; return false">Yahoo</a>

  10. Florchakh says:

    Thanks Mark. Could you test it in IE7?

  11. Hide Links in Status Bar says:

    [...] to use some dirty tricks like me on previous post (sorry for that). I’ve found a simple code from THIS blog(Florchakh Dot [...]

  12. Jack says:

    unfortunately this doesn’t work if people just right-click and open it in a new window in ff
    nice info anyway
    thanks

  13. Florchakh says:

    Well, at least you can use AJAX to develop your own context menu. It works pretty fine in Firefox ;)

  14. Link Mask Redirect and Cloaking Script says:

    Your javascript works great in IE 7. (At least in my version which is being run on WinXP) I hovered over it and say “yahoo.com” but when I clicked on it, it sent me to google

  15. Florchakh says:

    Thanks Steve, I’ve added one another update to this post!

  16. Arty says:

    It doesn’t work in new TAB… 8/

  17. mark rushworth says:

    How about just using javascript to document.write the links onto the page?

  18. Florchakh says:

    @ Arty: Yes it doesn’t, if you need it working “in new tab” you should read comments above

    @ Mark Rushworth: As far as JS cannot affect browser status bar there’s no need of using it. Notice - I wanted to make fake links that look like normal ones!

  19. guru crusher says:

    works wonderfuly for hiding affiliate links. Thanks

  20. billy says:

    Great read! Im glad i got the chance to read this! Keep up the great work!

  21. Zarada na Internetu says:

    Is there a way to add rel nofoollow and target*blank in this code ?

  22. Bart says:

    @Zarada: Yes, of course you can add various features. Honestly, you’re limited only by base capabilities of JavaScript. In case of opening new windows - check this out http://www.pageresource.com/jscript/jwinopen.htm

  23. Jerry says:

    Thanks! It doesn’t work if you right click and open the link in a new tab. It goes straight to yahoo.com, why?

  24. Jerry says:

    After reading my last comment, it seemed a little rude after reading it. I didn’t mean for it to come out like that. I really enjoyed the post and the tip.

  25. Bart says:

    Well, you didn’t read the comment section below this post, didn’t you? :mrgreen:

    The thing doesn’t work when you open the new tab. For the right mouse button you need to create fake context menu, I’d say there should be also some browser detection so you don’t show the script designed for IE to all Firefox users visiting your site. Take a look at one of the previous comments.

Leave a Reply