Access Clipboard using Js + Flash

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.