jquery implementation copied to the Clipboard

Source: Internet
Author: User

Some time ago you need to do a click on a button to copy the contents to the Clipboard effect.

For IE, there is an easy way to do this by Window.clipboarddata:

(If there is a button with ID of copy, there is an input box with ID name, "text" is a fixed format)

$ ("#copy"). Click (function  () {Window.clipboardData.setData ("text", $ ("#name"). Val ()); Alert ("copied to clipboard");});


However, this method is limited to IE browser, other browsers can not be used, so it is not recommended.

Here's a way to be compatible with mainstream browsers: jquery's Zclip plugin.

1, first download a zclip plug-in, the internet has a lot of download resources, a random Baidu, there are mainly two files: Jquery.zclip.min, zeroclipboard.swf. (Note that all two will be imported)

2, the two files are put in the project, while quoting JS for example: <script src= ". /plugins/js/jquery.zclip.min.js "></script> (my JS files are placed in the JS file under the plugins file in the root directory)

3, the following simulation of the specific code:

<a href= "www.baidu.com" id= "url" >www.baidu.com</a><input type= "button" value= "copy" id= "Copy"/> 

Click on the "Copy" button:

$ ("#copy"": /plugins/js/zeroclipboard.swf "function () {//return $ (" #url "   function () {//alert ("copied to clipboard");});

Where path is the path location of zeroclipboard.swf in the project, Aftercopy is optional.

jquery implementation copied to the Clipboard

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.