Skip to content

Commit 642bc63

Browse files
committed
New: Copy text to clipbox.
1 parent 34b0390 commit 642bc63

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

dom/copy_text.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
function copyToClipboard() {
2+
// Get the data to copy
3+
var data = document.getElementById("dataToCopy").innerText;
4+
5+
// Create a temporary textarea element
6+
var tempTextarea = document.createElement("textarea");
7+
tempTextarea.value = data;
8+
document.body.appendChild(tempTextarea);
9+
10+
// Select the text and copy it to clipboard
11+
tempTextarea.select();
12+
document.execCommand("copy");
13+
14+
// Remove the temporary element
15+
document.body.removeChild(tempTextarea);
16+
}
17+

0 commit comments

Comments
 (0)