I made a bookmark that users can add and it sends them to my site capturing the referrer.
<a href="javascript:location='http://www.chusmix.com/tests/?ref='+escape(location.href);" onclick="alert('Drag it, not click it!');return false;"> Bookmark </a>
My problem is that for some reason the location.href part instead of printing http:// it prints: "http%3A//". I want to remove it and get just the domain.com
I have a similar code that maybe could be useful but I'm having a hard time figuring out how to implement it inside HTML.
// Function to clean url
function cleanURL(url)
{
if(url.match(/http:\/\//))
{
url = url.substring(7);
}
if(url.match(/^www\./))
{
url = url.substring(4);
}
url = "www.chusmix.com/tests/?ref=www." + url;
return url;
}
</script>
Thanks
location.hrefyouescape(which is obsolete btw, you should useencodeURIComponent()), will be evaluated at runtime, i.e. if a user clicks this bookmark, thelocation.hrefof the page he is currently viewing would be sent, which is most likely not the same page as at the time he bookmarked one of your pages.location.hrefcan cause privacy problems, when used in a bookmark. Imagine a user is viewing a page that he definitely wants to keep private to himself. Clicking the bookmark while viewing that private page would expose it to your website. I doubt all users are aware what they send when clicking such bookmark, as there was another page context active the time dragging the link into the toolbar.