Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

People also ask

How do I copy and paste text in jQuery?

You can simply use jQuery to get the value of the original and paste it into the <textarea> like so: $("#copy"). click(function() { $("#paste").

How do you copy text to clipboard on a button click?

The next most common work-around is to just place the clipboard-bound text into an input field, move the focus to that field and advise the user to press Ctrl + C to copy the text.

Can JavaScript copy to clipboard?

select() to select the contents of the <textarea> element. Use Document. execCommand('copy') to copy the contents of the <textarea> to the clipboard.


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