Copy text to clipboard using javascript

Copy & Paste is most common function used among web users. It’s simple in web environment to select text and copy text to clipboard using Ctrl C key but sometimes we may have long text/content in the page which may be output which end user wants to print/copy in text files. In such case, It’s required to provide one button clicking on which it will copy long text to client’s clipboard.

This functionality can be achieved using  window.clipboardData.setData java script method but hold on 🙂 , this is supported in IE and Crome only. This is not working in firefox. Due to security issue, most of the modern browser has depreciated support of this method so the only simple solution is to provide alert message to user that the functionality will work only with IE and Crome if the page is opened in firefox.

There are some other alternatives like using flash object and third party like ZeroClipboard but I like simple solution for any problem so prefer go with first solution which I explained above.

Refer below links for more technical details.

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s