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