How to copy text to the client's clipboard using jQuery?

JavascriptJqueryBrowserClipboardCopy Paste

Javascript Problem Overview


The workflow is simple:

  1. You click inside a textarea.
  2. The text is copied to the client's clipboard.
  3. Display notice to the user.

How do you do it?

Javascript Solutions


Solution 1 - Javascript

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);
}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionmagerView Question on Stackoverflow
Solution 1 - JavascripthalocursedView Answer on Stackoverflow