-4

I already have it set up to where the page URL dynamically becomes the value of href (I can change the attribute or add one if needed). How can I make the link copy the href value to the clipboard?

I'm not looking for how to copy text from some other element by calling on it's id or class, I'm trying to make the link copy the text from the attribute in itself.

<li><a href='page.url'><i class='material-icons'>content_copy</i></a></li>
gio1135
  • 87
  • 2
  • 9
  • 2
    Did you have a look at this? https://stackoverflow.com/questions/400212/how-do-i-copy-to-the-clipboard-in-javascript?answertab=votes#tab-top – Sebastian Kaczmarek Oct 11 '17 at 19:11
  • Possible duplicate of [How do I copy to the clipboard in JavaScript?](https://stackoverflow.com/questions/400212/how-do-i-copy-to-the-clipboard-in-javascript) – glennsl Oct 11 '17 at 19:39

1 Answers1

2

Don't recommend rolling out your own solution due to browser support quirks, however, there's a fully tested and trusted small 2 file library that already solves this problem (almost 20k stars on GitHub) clipboard.js that you should consider using, hope this helped you out.

linasmnew
  • 3,907
  • 2
  • 20
  • 33