Way to copy to clipboard in the PURE javascript?

For security reasons most browsers do not allow to modify the clipboard (except IE).

The only way to make a copy-to-clipboard function cross-browser compatible is to use Flash.

For now you can select all the data you want to copy, and ask user to click CTRL+C.


There is currently no way to do that cross-browser (often disabled for security reasons). In older browsers there is no such functionality (security issues) or often must be turned on manually... But in older browsers there is a high possibility of doing this using Flash...

UPDATE 2016
Still not mobile-cross-browser, but supported in newset desktop versions of major browsers...
Mozilla developer docs have now a little better description of Document.execCommand() and specifically the "copy" command:

Copies the current selection to the clipboard. Conditions of having this behavior enabled vary from one browser to another, and have evolved over time. Check the compatibility table to determine if you can use it in your case.

GREAT NEWS! (UPDATE 2016-08)

Copy/cut adopted by all of the current major desktop browsers!

Compatibility tables (2016-08-10) (source: Mozilla Dev)

Desktop

JavaScript copy execCommand compatibility table DESKTOP

Mobile

JavaScript copy execCommand compatibility table MOBILE 2017-03-05 (both desktop&mobile): Edge - basic support & copy/cut: Yes, Chrome copy/cut support changed to 43.

Quote about "the Firefox way"

There is a possibility that this will be done the same way in other browsers in the future:

Before Firefox 41, clipboard capability needed to be enabled in the user.js preference file. See A brief guide to Mozilla preferences for more information. If the command wasn't supported or enabled, execCommand was raising an exception instead of returning false.
In Firefox 41 and later, clipboard capability are enabled by default in any event handler that is able to pop-up a window (semi-trusted scripts).

This means, it is highly possible that any browser supporting copy/cut will do that only on user action. E.g.: Calling copy command on the fly won't work, however if bound to a click event, it works, even when the event is not prevented (e.g. navigation) (Chrome tested).

And here is some interesting article from Google, describing also the Selection API: https://developers.google.com/web/updates/2015/04/cut-and-copy-commands

BTW: Of course you could preselect the text and ask user to click CTRL+C but you lose user-experience.