How to copy text to the client’s clipboard using jQuery? [duplicate]

How to copy text to the client’s clipboard using jQuery? [duplicate]

This question already has an answer here:

How do I copy to the clipboard in JavaScript?

51 answers

The workflow is simple:

You click inside a textarea.
The text is copied to the client’s clipboard.
Display notice to the user.

How do you do it?

Solutions/Answers:

Solution 1:

Copying to the clipboard is a tricky task to do in Javascript in terms of browser compatibility. The best way to do it is using a small flash. It will work on every browser. You can check it in this article.

Here’s how to do it for Internet Explorer:

function copy (str)
{
    //for IE ONLY!
    window.clipboardData.setData('Text',str);
}

Related:  How to use MongoDB with promises in Node.js?