Jquery-zclip is a jquery plugin that replicates content to the Clipboard, and we don't have to consider compatibility issues between different browsers and browser versions. Jquery-zclip plug-in requires Flash support, remember to install Adobe Flash Player when you use it.
To load jquery and zclip, please change the address according to their respective storage address.
<script type= "Text/javascript" src= "js/jquery.js" ></script><script type= "Text/javascript" src= "js/ Jquery.zclip.min.js "></script>
JS implementation Click to copy the code (local test can not be used, upload to the server test)
$ (function () {$ (' #copy_input '). Zclip ({path: ' js/zeroclipboard.swf ', copy:function () {//copy content return $ (' #mytext '). Val (); }, Aftercopy:function () {///Copy succeeded $ ("<span id= ' msg '/>"). InsertAfter ($ (' #copy_input ')). Text (' copy succeeded '); } });});
Note that if the copied content comes from input box inputs, textarea, and so on, the Copy object uses:
Copy:function () {return $ (' #mytext '). Val ();
If the copied content comes from a page element Div, p, and so on, the Copy object uses:
Copy: $ (' #mytext '). Text ();
Configuration Instructions
path:swf path (replication is mainly used to resolve the replication of different browsers with Flash) copy: The content to be copied, can be static content, can also return dynamic content beforecopy: Copy before the function;aftercopy: function to be done after copying;
3 methods are available
Show:$ (selected). Zclip (' show '); The copy function is valid hide:$ (selected). Zclip (' hide '); The copy function is invalid remove:$ (selected). Zclip (' remove '); Complete removal of replication functionality
After successful operation, click the Copy button and a prompt will pop up indicating that the copy to the Clipboard is in effect.
Pop-up box appears "Copied Text to Clipboard" English characters, a bit inconsistent with the Chinese people use the habit, change it to "successfully copied to the Clipboard", in the Jquery.zclip.min.js file found "Copied text to clipboard" replaced by "Successfully copied to the Clipboard" will be OK.
For more information, please refer to http://www.steamdev.com/zclip/
Disclaimer: This article uses BY-NC-SA agreement to authorize, reprint also please specify: Jquery+flash (zclip) realize click Copy to Clipboard
Jquery+flash (Zclip) enables click to copy to Clipboard