Libraryless. Click here for Pure Java version (2758L/17K).
1 | // by Angelos Chalaris, https://www.30secondsofcode.org/blog/s/copy-text-to-clipboard-with-javascript |
2 | static JavaScript hjs_copyToClipboard() {
|
3 | ret JavaScript([[ |
4 | const copyToClipboard = str => {
|
5 | const el = document.createElement('textarea');
|
6 | el.value = str; |
7 | el.setAttribute('readonly', '');
|
8 | el.style.position = 'absolute'; |
9 | el.style.left = '-9999px'; |
10 | document.body.appendChild(el); |
11 | const selected = |
12 | document.getSelection().rangeCount > 0 ? document.getSelection().getRangeAt(0) : false; |
13 | el.select(); |
14 | document.execCommand('copy');
|
15 | document.body.removeChild(el); |
16 | if (selected) {
|
17 | document.getSelection().removeAllRanges(); |
18 | document.getSelection().addRange(selected); |
19 | } |
20 | }; |
21 | ]]); |
22 | } |
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: | 463 / 596 |
| Version history: | 1 change(s) |
| Referenced in: | [show references] |