Test case for copying test with native APIs. (Works on latest Chrome, Firefox, Safari.)
made with esnextbin
Test case for copying test with native APIs. (Works on latest Chrome, Firefox, Safari.)
made with esnextbin
<!doctype html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>Browser copy</title> | |
</head> | |
<body> | |
<input type="text" id="text" value="hello" /> | |
<button id="copy">Copy</button> | |
</body> | |
</html> |
document.getElementById('copy').addEventListener('click', e => { | |
const text = document.getElementById('text') | |
text.focus() | |
text.setSelectionRange(0, text.value.length) | |
// document.execCommand('selectAll') | |
// this works in safari and chrome, but not in firefox; unless it's a contenteditable | |
document.execCommand('copy') | |
text.blur() | |
}) |
{ | |
"name": "browser-copy", | |
"version": "0.0.0" | |
} |