Monday, March 25, 2013

Copy to Clipboard

Problem:
Copying something to the clipboard was always something I found interesting, but never had to implement it until now.

Solution:
There are various ways to accomplish this, however the issue is getting it to work on the various browsers and operating systems.

- Using Flash (.swf) (problems with flash versions)
- Using window.clipboardData.setData('Text', 'text to copy'); (only works with IE)
- Other options and plugins (http://archive.plugins.jquery.com/project/clipboard) (deprecated)
- Using a dialog window with the text pre-selected, so that the user only needs to CTRL+C

function copyToClipboard (text) {
  window.prompt ("Copy to clipboard: Ctrl+C, Enter", text);
}



Stack Overflow post,
http://stackoverflow.com/questions/400212/how-to-copy-to-the-clipboard-in-javascript

http://stackoverflow.com/questions/1539641/copy-text-to-the-clients-clipboard-using-jquery

Extended clipboard ways post,
http://brooknovak.wordpress.com/2009/07/28/accessing-the-system-clipboard-with-javascript/

No comments:

Post a Comment