Luis Gallego Luis Gallego - 4 months ago 13
HTML Question

How to copy a div's content to clipboard without flash

That's it :) I have a div with the id #toCopy, and a button with the id #copy.
What's the best way to copy #toCopy content to clipboard when pressing #copy?

Answer

UPDATED ANSWER Javascript was restricted from using the clipboard, early on. but nowadays it supports copy/paste commands. See documentation of mozilla and caniuse.com.

document.execCommand('paste')

make sure that you support browsers that don't.

https://developer.mozilla.org/en-US/docs/Web/API/Document/execCommand http://caniuse.com/#search=command

Javascript is not allowed to use the clipboard, but other plugins like flash do have access.

How do I copy to the clipboard in JavaScript?