wayne on March 20, 2008
Sometimes you build a site and think, I really don't want people seeing who I'm linking up to. There could be a variety of reasons of why you would want to. This isn't that post. This post simply lays out one method to mask URL's in your hyperlinks.
To mask your links, simply add the following JavaScript to your page, somewhere close to your opening <body> tag, but after it:
<script type="text/javascript">
<!--
function GetResource(url){window.location = url;}
function GetNewResource(url){window.open(url);}
//-->
</script>
The two functions perform the redirect, each a bit differently. The GetResource(Url) routine accepts the Url and changes the current widow location to the provided Url. The GetNewResource opens a new browser window and navigates to the provided Url.
With that in place, we now need to modify all the links on the page that we don't want the user to readily know who we are linking to. This is accomplished by making the statusbar in the browser display a # symbol. Our next step is to modify the links on the page.
From this:
<a href="http://www.MyAffiliateLink.com/blah/blah.bla">Not a masked link</a>
To this:
<a href="#" onclick="javascript:GetResource('http://www.MyAffiliateLink.com/blah.bla')">
A Masked Link</a>
How you modify the links on your pages is another post entirely, but if you just have static Html files and not many files, you can parse though this by hand. If you're your on the programming side you can parse the Html prior to it being written to the client, modifying the links as you go.