Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <script>
- function addWeirdTextToClipboard () {
- var container = document.getElementById('container'),
- editingDiv = document.createElement('div'),
- text = document.createTextNode('the weird text'),
- range = document.createRange();;
- editingDiv.appendChild(text);
- editingDiv.setAttribute('contentEditable',true)
- container.appendChild(editingDiv);
- range.selectNodeContents(editingDiv);
- window.getSelection().addRange(range);
- document.execCommand('copy', false, null);
- container.removeChild(editingDiv);
- }
- </script>
- </head>
- <body>
- <button onclick="addWeirdTextToClipboard()">I want free icecream!</button>
- <div id="container"></div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement