Libraryless. Click here for Pure Java version (2758L/17K).
// by Angelos Chalaris, https://www.30secondsofcode.org/blog/s/copy-text-to-clipboard-with-javascript static JavaScript hjs_copyToClipboard() { ret JavaScript([[ const copyToClipboard = str => { const el = document.createElement('textarea'); el.value = str; el.setAttribute('readonly', ''); el.style.position = 'absolute'; el.style.left = '-9999px'; document.body.appendChild(el); const selected = document.getSelection().rangeCount > 0 ? document.getSelection().getRangeAt(0) : false; el.select(); document.execCommand('copy'); document.body.removeChild(el); if (selected) { document.getSelection().removeAllRanges(); document.getSelection().addRange(selected); } }; ]]); }
download show line numbers debug dex old transpilations
Travelled to 6 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt
No comments. add comment
| Snippet ID: | #1029722 |
| Snippet name: | hjs_copyToClipboard - function that copies text to clipboard |
| Eternal ID of this version: | #1029722/2 |
| Text MD5: | e1eb39454fd69c881716ee3bdcf1ec30 |
| Transpilation MD5: | ed418e6cdbe80ea64c5683e7d79f246a |
| Author: | stefan |
| Category: | javax |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2020-09-09 13:07:02 |
| Source code size: | 803 bytes / 22 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 461 / 592 |
| Version history: | 1 change(s) |
| Referenced in: | [show references] |