Created
July 27, 2020 10:47
-
-
Save saravanakumarputta/6981fbdb22b603c69e5abd316b399821 to your computer and use it in GitHub Desktop.
Copy Text 2 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 lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Copy Text 2 Clipboard</title> | |
</head> | |
<body> | |
<div> | |
<input type="text" id="text" placeholder="Enter text" /> | |
<button onClick="copyTextToClipBoard()">Copy To ClipBoard</button> | |
</div> | |
<script> | |
function copyTextToClipBoard() { | |
//Input Element with id "text" | |
let textToBeCopied = document.getElementById('text'); | |
//Select the content in the input element | |
textToBeCopied.select(); | |
textToBeCopied.setSelectionRange(0, 99999); | |
//copy the text inside the input element to clipboard | |
document.execCommand('copy'); | |
alert('Text copied to Clipboard'); | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment