text-programmatic-copy.html 657 B

123456789101112131415161718192021222324252627
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <title>text-programmatic-copy</title>
  6. <meta name="viewport" content="width=device-width, initial-scale=1" />
  7. </head>
  8. <body>
  9. <!-- 1. Define some markup -->
  10. <button id="btn">
  11. Copy
  12. </button>
  13. <!-- 2. Include library -->
  14. <script src="../dist/clipboard.min.js"></script>
  15. <!-- 3. Instantiate clipboard -->
  16. <script>
  17. var btn = document.querySelector('#btn');
  18. btn.addEventListener('click', () => {
  19. const textCopied = ClipboardJS.copy('123');
  20. console.log('copied!', textCopied);
  21. })
  22. </script>
  23. </body>
  24. </html>