0

Sorry if this is very simple, I am extremely new to code. I have this button but I cannot find a way to copy it's link when it's clicked. I just want someone to be able to click the button, copy it to their clipboard, and have a popup say "Link Copied". How do I do this? Thank you for any help you can provide.

<a href="http://google.com" class="videotabsbutton w-button">Copy</a>
  • 2
    Does this answer your question? [How do I copy to the clipboard in JavaScript?](https://stackoverflow.com/questions/400212/how-do-i-copy-to-the-clipboard-in-javascript) – idmean Feb 03 '21 at 18:18
  • Refer to this [link](https://www.w3schools.com/howto/howto_js_copy_clipboard.asp) – Vaibhav Feb 03 '21 at 18:18

1 Answers1

1
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<body>

<a href="http://google.com" class="videotabsbutton w-button" onclick='return copyToClipboard(this)'>Copy</a>

<script>
function copyToClipboard(element) {
    var $temp = $("<input>");
    $("body").append($temp);
    $temp.val($(element).attr('href')).select();
    document.execCommand("copy");
    $temp.remove();
    alert("Link copied!");

}

</script>
</body>
</html>

this should work. Got it from here: Click button copy to clipboard using jQuery

twiddler
  • 588
  • 4
  • 16