Guest User

Untitled

a guest
Jun 22nd, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.  
  4. <head>
  5. <title></title>
  6. <style type="text/css">
  7. .copyInput {
  8. border: none;
  9. overflow: auto;
  10. outline: none;
  11. -webkit-box-shadow: none;
  12. -moz-box-shadow: none;
  13. box-shadow: none;
  14. width: 0px;
  15. height: 0px;
  16. position: absolute;
  17. opacity: 0;
  18. }
  19.  
  20. #thaSpan {
  21. cursor: pointer;
  22. }
  23. </style>
  24. </head>
  25.  
  26. <body>
  27. <span id="thaSpan">The brown lazy fox</span>
  28. <script>
  29. bindCopy('thaSpan');
  30.  
  31. function bindCopy(spanSelector, callback) {
  32. let span = document.getElementById(spanSelector);
  33. span.addEventListener('click', copySpan, false);
  34. function copySpan() {
  35. let input = document.createElement('textarea');
  36. input.readOnly = true;
  37. input.className += ' copyInput';
  38. document.body.appendChild(input);
  39. input.value = span.innerHTML;
  40. input.select();
  41. document.execCommand("Copy");
  42. setTimeout(function() {
  43. input.selectionEnd = input.selectionStart;
  44. input.blur();
  45. input.parentNode.removeChild(input);
  46. if (typeof callback === 'function') callback();
  47. }, 1);
  48. }
  49. }
  50. </script>
  51. </body>
  52.  
  53. </html>
Add Comment
Please, Sign In to add comment