Advertisement
MADmadisson

Code box with Copy Text Button

Sep 28th, 2023
1,214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.24 KB | None | 0 0
  1. <button onclick="myFunction()" style="color:#783f04;background-color: rgba(252,229,205,1);border-color: rgba(252,229,205,1);height: 27.0pt;font-size: 13.0pt;font-weight: 700;font-family: 'Nunito', sans-serif;border-radius: 4px;transition: background .2s .1s;width: 100%;border-style: solid;">Copy Text</button><br>
  2. <div style="margin-top:10px;background-color:#0000000f;padding: 10px;border-radius: 10px;"><textarea type="text" style="height:100px;border: none;position: relative;width: 100%;background-color: transparent;color: #666666;font-family: Courier;" id="myInput">
  3.  
  4. TEXT GOES HERE
  5.  
  6.  
  7. </textarea></div>
  8.  
  9.  
  10.  
  11. <script>
  12. function myFunction() {
  13.   // Get the text field
  14.   var copyText = document.getElementById("myInput");
  15.  
  16.   // Select the text field
  17.   copyText.select();
  18.   copyText.setSelectionRange(0, 99999); // For mobile devices
  19.  
  20.   // Copy the text inside the text field
  21.   navigator.clipboard.writeText(copyText.value);
  22.  
  23.   // Alert the copied text
  24.   alert("Copied the text: " + copyText.value);
  25. }
  26. </script>
  27. <link rel="preconnect" href="https://fonts.googleapis.com">
  28. <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
  29. <link href="https://fonts.googleapis.com/css2?family=Nunito:wght@700&display=swap" rel="stylesheet">
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement