• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1663
  • Last Modified:

Copy URL to clipboard

Hi there

Wonder if you can help me?

I have the following code:

<a href="#" id="123" onclick="copy('http://www.google.com','123')">Copy Me</a>
<a href="#" id="ABC" onclick="copy('http://www.yahoo.com','ABC')">Copy Me</a>
<a href="#" id="007" onclick="copy('http://www.youtube.com','007')">Copy Me</a>
<a href="#" id="MLOP" onclick="copy('http://www.FT.com','MLOP')">Copy Me</a>

If a user clicks on let say the 1st Copy Me it will run the JS function called copy, what that will do is copy the URL to the clipboard and after it would prompt them with, "The URL has been saved to the clipboard"

So, clicking on the 1st Copy Me

It should copy http://www.google.com

if I click on the 3rd Copy Me it should copy http://www.youtube.com into the clipboard.

Hope that makes sense?

1 Solution
have a function like this and  pass the value

function copyToClipboard(s)
      if( window.clipboardData && clipboardData.setData )
            clipboardData.setData("Text", s);
mousemat24Author Commented:
thank you so much for that contactkarthi
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now