Advertisement
chernov2000

Копировать в буфер

Aug 23rd, 2023
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4.  
  5. <p>Click on the button to copy the text from the text field. Try to paste the text (e.g. ctrl+v) afterwards in a different window, to see the effect.</p>
  6.  
  7. <input type="text" value="Hello World" id="myInput">
  8. <button onclick="myFunction()">Copy text</button>
  9.  
  10. <script>
  11. function myFunction() {
  12. // Get the text field
  13. var copyText = document.getElementById("myInput");
  14.  
  15. // Select the text field
  16. copyText.select();
  17. copyText.setSelectionRange(0, 99999); // For mobile devices
  18.  
  19. // Copy the text inside the text field
  20. navigator.clipboard.writeText(copyText.value);
  21.  
  22. // Alert the copied text
  23. alert("Copied the text: " + copyText.value);
  24. }
  25. </script>
  26.  
  27. </body>
  28. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement