Reputation: 11
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>
Upvotes: 0
Views: 959
Reputation: 588
<!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
Upvotes: 1