Recently, I have encountered this problem. click the button to copy the link. Finally, the solution ZeroClipBoard is an open-source js + Flash implementation clipboard operation.
However, after searching for many examples, we found that most of them are about a page with only one fixed copy operation.
And I need
A dynamic Repeater dynamically loads the addresses and copy buttons.
The principle of this solution is:
Dynamically load a transparent flash with js. then cover the button you want to click, and then bind the event to the flash bearing element to dynamically transfer the copied value to the flash, and access the clipboard with flash.
At this time, there is such a problem. If each button is added with flash, it will eat a lot of memory and the dynamic code is not very easy to write.
The final solution is as follows:
Copy codeThe Code is as follows: <divid = "ClipSwf" style = "left:-1000px; position: absolute; width: 80px; height: 25px;"> </div>
1. now place a hidden flash container in the Body for absolute positioningCopy codeThe Code is as follows: varLocalUrlManage = {
Clip: null,
ClipContainer: null,
InitClip: function (){
LocalUrlManage. Clip = newZeroClipboard. Client ();
LocalUrlManage. ClipContainer =$ ("# ClipSwf ");
LocalUrlManage. Clip. setHandCursor (true );
LocalUrlManage. Clip. setCSSEffects (true );
LocalUrlManage. Clip. addEventListener ("complete", function (client, text ){
Tip. RightTip ("# UrlAdd", text + "," + "Copied successfully! ");
});
LocalUrlManage.ClipContainer.html (LocalUrlManage. Clip. getHTML (80, 25 ));
}}
2. Use js to initialize the clipboard object when page loading is complete, set the mouse gesture and carry the container, and then output the flash into html to the container.Copy codeThe Code is as follows: onmouseover = "LocalUrlManage. SetClipValue (this, '# copyUrlValue <% # Eval (" Id ") %>')"> click Copy </button>
Copy codeThe Code is as follows: SetClipValue: function (obj, SelectorEl ){
// BrowserClip. IEClip ($ (SelectorEl). val ());
Varoffset = $ (obj). offset ();
LocalUrlManage. ClipContainer. offset ({left: offset. left, top: offset. top });
LocalUrlManage. Clip. setText ($ (SelectorEl). val ());
}.
3. dynamically bind events on each copy button and pass the copied value or control of the response to the function. Then, set left to hide the flash container, top margin let it float on the button that triggers the event and pass the value to be copied
Clip. setText ('text') (method provided by the plug-in) is passed to flash, so that multiple buttons can be copied.
The problem persists. The original hovercss switch effect is not flexible after flash is covered. It is not very effective to dynamically add styles with jquery.