I want to be able to have the user click a button and have javascript copy some certain text into their clipboard. I was able to get this to work using a , where any value they put in would be copied, but is there any way I can do it with just a and some ?
I tried the following:
<html>
<head>
<title>
</title>
</head>
<body>
<button id='myBtn' onclick='myFunction()'>Click Me</button>
</body>
<script>
function myFunction() {
var copyText = 'CopiedText';
copyText.select();
copyText.setSelectionRange(0, 99999)
document.execCommand("copy");
alert("Copied the text: " + copyText.value);
}
</script>
</html>