Created
November 15, 2017 09:16
-
-
Save Sanix-Darker/667dad787e7392b48baa66408d200174 to your computer and use it in GitHub Desktop.
[JS] Copy 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
<input name="exampleClipboard" placeholder="Insert the text you want to copy" value="Example text" tabindex="1" autocomplete="off" maxlength="240" style="width:200px" type="text"> | |
<p> | |
<button id="copy"> | |
Copy text | |
</button> | |
</p> | |
<p> | |
Right click paste or Ctr + v after click Copytext button <br/> | |
<textarea></textarea> | |
</p> | |
<script> | |
function copyToClipboard() { | |
document.querySelector('input').select(); | |
document.execCommand('copy'); | |
//clear selection | |
if ( document.selection ) { | |
document.selection.empty(); | |
} else if ( window.getSelection ) { | |
window.getSelection().removeAllRanges(); | |
} | |
} | |
document.querySelector('#copy').addEventListener('click', function() { | |
copyToClipboard() | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment