This page is read only. You can view the source, but not change it. Ask your administrator if you think this is wrong. ====== Copy Button ====== Copies the button contents to the clipboard. Issues getting it working. <html> <button id="copy-button">Copy this Text to Clipboard</button> <br><br> <input placeholder="Paste here, to try!"> </html> <html> <script> function copyById(containerId) { var range_ = document.createRange(); // create new Range object range_.selectNode(document.getElementById(containerId)); // set our Range to contain the Node we want to copy from window.getSelection().removeAllRanges(); // remove any previous selections window.getSelection().addRange(range_); // select document.execCommand("copy"); // copy to clipboard window.getSelection().removeAllRanges(); // remove selection } // add onClick event handler to your button with additional function() to not invoke copyById immediately: document.getElementById('copy-button').onclick = function() { copyById('copy-button'); } </script> </html> Last modified: 2021/07/09 15:48by big_josh_energy Log In