Source Code:
(back to article)
Submit
Result:
Report an issue
<!DOCTYPE html> <html> <head> <title>Title of the document</title> </head> <body> <textarea id="textId">Some copying text</textarea> <button id="copyBtn">Copy Button</button> <script> document.getElementById("copyBtn").onclick = function() { let text = document.getElementById("textId").value; copyTextToClipboard(text); } async function copyTextToClipboard(text) { try { await navigator.clipboard.writeText(text); alert('Text copied to clipboard'); } catch(err) { alert('Error in copying text: ', err); } } </script> </body> </html>