जावास्क्रिप्ट के साथ वेब पेज पर 'कॉपी टू क्लिपबोर्ड' फीचर बनाने के लिए कोड निम्नलिखित है:
उदाहरण
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Document</title> <style> body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result { font-size: 18px; font-weight: 500; color: rebeccapurple; } input, button { padding: 8px; } </style> </head> <body> <h1>Creating Copy to Clipboard</h1> <input class="textCopy" type="text" /> <button class="Btn">Copy Text</button><br /><br /> <input type="text" placeholder="paste here" /> <h3>Click on the above button to copy text from the textbox</h3> <script> let resEle = document.querySelector(".result"); let BtnEle = document.querySelector(".Btn"); let textCopyEle = document.querySelector(".textCopy"); BtnEle.addEventListener("click", () => { textCopyEle.select(); document.execCommand("copy"); }); </script> </body> </html>
आउटपुट

पहले टेक्स्टबॉक्स में कुछ टाइप करके "Copy Text" बटन पर क्लिक करने पर:

"paste here" टेक्स्टबॉक्स में लेफ्ट क्लिक करके पेस्ट सेलेक्ट करके टेक्स्ट पेस्ट करने पर:
