Created
July 21, 2019 05:06
-
-
Save onuproy/c80d1ed2c863b5bac89ba610d61a8a1d to your computer and use it in GitHub Desktop.
Copy Text to Clipboard
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<body> | |
<p>Click on the button to copy</p> | |
<input type="text" value="Hello World" id="myInput"> | |
<button onclick="myFunction()">Copy text</button> | |
<p>The document.execCommand() method is not supported in IE8 and earlier.</p> | |
<script> | |
function myFunction() { | |
var copyText = document.getElementById("myInput"); | |
copyText.select(); | |
document.execCommand("copy"); | |
alert("Copied the text: " + copyText.value); | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It's code is very helpful