Forum Moderators: open

Message Too Old, No Replies

Save to clipboard

         

dektek11

10:14 am on Jan 27, 2005 (gmt 0)

10+ Year Member



On certain sites it will output information into a field that is automatically highlighted and has a button to copy to clipboard. Does anyone know how to set that up? (with auto-highlight or a highlight and/or copy button)

BlobFisk

1:30 pm on Jan 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



AFAIK this is something that you can only do in IE and uses an MS method called execCommand.


function copyToClipboard(textareaID) {
// Get the text in the textarea
theText = document.getElementById(textareaID).innerText;
// Create a textRange for the clipboad
copyText = theText.createTextRange();
// Remove any formatting, this allows you to copy code etc.!
copyText.execCommand("RemoveFormat");
// Copy the text to the clipboard
copyText.execCommand("Copy");
}

More on execCommand can be found on MSDN [msdn.microsoft.com].

HTH