Append current url to existing link with javascript

Hi I have this link

http://www.facebook.com/sharer.php?u=

I want to append the current url to it and make thw whole thing a link. I’ve got the below code which is almost working I’m just not sure of how to append the link to the window.location part. ANy help would be great. Thanks

BELOW CODE NOT WORKING


 document.getElementById("facebook").href = "http://www.facebook.com/sharer.php?u=".window.location.toString();


Hi,

Something like this?

<a href="http://www.facebook.com/sharer.php?u=" id="facebook">FaceBook Link</a>

var link = document.getElementById("facebook"),
    currUrl = document.URL;

link.href = link.href + currUrl;

Thanks this is working. Cheers

No probs :slight_smile:
Thanks for taking the time to report back.