Copy content to the Clipboard through JS, but if you take into account the compatibility of the browser problem, it becomes a bit of trouble, with the help of Flash browser compatibility
If you want to copy content to the Clipboard through JS, it would not be difficult, but if you consider the compatibility of the browser problem, it becomes a bit of trouble, using Jquery-zclip replication is a good choice, with the help of Flash browser compatible. The principle is not detailed, the following next how to achieve. For example, my HTML code is: code as follows: <div class= "Buttonbox" > <code rel= "1" ><span id= "Id_1" > Content to replicate 1</span></code> <code rel= "2" ><span id= "id_2" > Content to replicate 2</span></code > <code rel= "3" ><span id= "Id_3" > What to replicate 3</span></code> </div> JS file requires a total of two, jquery Needless to say, and then jquery-zclip.js and zeroclipboard.swf, these two documents can be downloaded on the official website, the address is as follows: http://www.steamdev.com /zclip/ Generate Copy button JS as follows code as follows: <script type= "Text/javascript" > $ (function () { $ ( ' Code '). each (function () { var self = $ (this); var id = self.attr (' rel '); var copy = $ (' <span> copy < /SPAN> '). Appendto (self). Zclip ({ ' path ': '/static/admin/js/zeroclipboard.swf ',//here write its own address ' Aftercopy ': function () { alert (' Get the address of the corresponding code has been copied to the Clipboard, you can use CTRL + V to paste '); }, ' copy ': function() { return $ (' #id_ ' +id). Text ()//note here, if Div span, etc. use text (), if input, use Val (), this support is not very good } }); } ; }); </script> This will allow time to replicate across the browser, it was not a very difficult thing, I did the test when it was very smooth, can when I put him in the project on the problem, Copy button production location no flash, only text, and later found that, in fact, Flash generated, but there is no text in the location, estimated and my project backstage use is the structure of the IFRAME, estimated that this is a bug bar this plugin, and later looked at a lot of information, some people say, Need to change the code on it, and then I changed, under, and sure enough the need to modify the code as follows code as follows: Getdomobjectposition:function (obj, stopobj) { //Get absolute coordinates for DOM element var info = { left:0, top:0, width:obj.width ? obj.width:obj.offsetwidth, height:obj.height? obj.height:obj.offsetheight }; if (obj && (obj!= stopobj) { //info.left + = Obj.offset Left; Before modification //info.top + = Obj.offsettop; Before modification JPOs = $ (obj). position (); Modified Info.left + = Jpos.left; Modified Info.top + = Jpos.top; Modified } return info; } In fact, this is related to the principle of the plugin, he will be a transparent flash overlay to the top of the button, ifThe two of them do not coincide, there is a problem.