Please see this article:
https://www.lucidchart.com/techblog/2014/12/02/definitive-guide-copying-pasting-javascript[
^].
See also:
http://stackoverflow.com/questions/400212/how-do-i-copy-to-the-clipboard-in-javascript[
^].
Note there is a pretty interesting trick described in the answer referenced above.
That said, browser make using clipboard pretty difficult, because automatic copy without the user consent it pretty dangerous; the user is unaware of that and can loose some data previously put to the clipboard.
So, better don't do it at all.
Here is my advice: find any CodeProject code sample, say, your own code sample on this very page. Please click on "Copy Code". Are you getting the idea?
So, this is what I advise: use the CodeProject way: this is the simplest and at the same time the safest solution.
—SA