Some time ago need to do a click a button to copy the design content to the Clipboard effect.
For IE browsers, there is an easy way to pass Window.clipboarddata:
(If there is a button with the ID 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");
});
But this method is limited to IE browser, other browsers can not use, so do not recommend use.
Here's a way to be compatible with a mainstream browser: jquery's Zclip plugin.
1, first download a Zclip plug-in, the internet has a lot of download resources, casual Baidu, which has two main files: Jquery.zclip.min, zeroclipboard.swf. (Note that two are imported)
2, the two files are put into the project, while referencing JS such as: <script src=. /plugins/js/jquery.zclip.min.js "></script> (my JS files are placed in the root directory under the plugins file under the JS file)
3, the following simulation of the specific code:
<a href= "www.baidu.com" id= "url" >www.baidu.com</a>
Click the "Copy" button:
$ ("#copy"). Zclip ({
<span style= "White-space:pre" > </span>path: ". /plugins/js/zeroclipboard.swf ",
<span style= "White-space:pre" > </span>copy:function () {<span style= "White-space:pre" >
<span style= "White-space:pre" > </span>return $ ("#url"). Text ();
<span style= "White-space:pre" > </span>},
<span style= "White-space:pre" >
<span style= "White-space:pre" > </span>alert ("copied to clipboard");
<span style= "White-space:pre" > </span>}
});
<span style= "Font-family:verdana, Arial, Helvetica, Sans-serif; Background-color:rgb (254, 254, 242); " > Where path is zeroclipboard.swf the path position in the project, aftercopy Optional. </span>