Advertisement
Guest User

copy random stuff

a guest
Aug 3rd, 2015
440
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. <html>
  2. <head>
  3. <script>
  4. function addWeirdTextToClipboard () {
  5. var container = document.getElementById('container'),
  6. editingDiv = document.createElement('div'),
  7. text = document.createTextNode('the weird text'),
  8. range = document.createRange();;
  9. editingDiv.appendChild(text);
  10. editingDiv.setAttribute('contentEditable',true)
  11. container.appendChild(editingDiv);
  12.  
  13. range.selectNodeContents(editingDiv);
  14. window.getSelection().addRange(range);
  15. document.execCommand('copy', false, null);
  16. container.removeChild(editingDiv);
  17.  
  18. }
  19. </script>
  20. </head>
  21. <body>
  22. <button onclick="addWeirdTextToClipboard()">I want free icecream!</button>
  23. <div id="container"></div>
  24. </body>
  25. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement