-5

I have a website that I want to insert in it some social buttons so users can share it on twitter and facebook. I want to get the page URL and insert it in in the share buttons.

How do I get the current page URL and use it in a <a href=""> tag or inside other parts on my HTML code?

I know about document.URL on javascript. I just don't know how to apply it on an tag.

Imnotapotato
  • 5,308
  • 13
  • 80
  • 147

1 Answers1

4

document.getElementById("myLink").href = document.URL;
<a id="myLink" href="">Click me I am a link</a>

Hover your mouse over the link to see which link.

Anwar
  • 4,162
  • 4
  • 41
  • 62