MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/JavaScriptTips/comments/10g5529/how_to_copy_text_to_clipboard_with_asyncawait/
r/JavaScriptTips • u/Low_Mammoth_9371 • Jan 19 '23
2 comments sorted by
1
Code to copy:
<input type="text" id="input"> <button onclick="copyToClipboard()">Copy to clipboard</button> <div id=output></div> <script> async function copyToClipboard(myText) { try { let input; input = document.getElementById('input').value; await navigator.clipboard.writeText(input); alert("Copy successful!") } catch { alert("Copy failed! "+ err); } } </script>
1
u/Low_Mammoth_9371 Jan 19 '23
Code to copy: