Js+flash implementation of access to the clipboard operation _javascript Skills

Source: Internet
Author: User
Recently need to encounter this problem click on the button to copy the link function decisive Niang google. Finally found the solution zeroclipboard an open source to js+flash implementation of the cut board operation
But after searching for a number of examples, it was found that most of the pages were about a single fixed copy operation.

And that's what I need.
A dynamic repeater dynamically loads each address and copy button.
The solution works by:
Take JS dynamic load a transparent flash. And then cover to the button you want to click, and then in the flash to the load element binding event dynamic to copy the value of the transfer to Flash, with flash access to the Clipboard.
That's when there's a problem. Multiple buttons if each button is added to the flash will be very eat memory and dynamic code is not very good to write
The final solution is as follows:
Copy Code code as follows:

<divid= "clipswf" style= "left:-1000px;position:absolute;width:80px;height:25px;" ></div>

1. Now the body to place a hidden flash container absolute positioning
Copy Code code 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+ "," + "copy successful!");
});
LocalUrlManage.ClipContainer.html (LocalUrlManage.Clip.getHTML (80,25));
}}

2. Use JS to initialize the object of the Clipboard when the page is loaded and set the mouse gesture and load container and then output the flash to the container in HTML
Copy Code code as follows:

Onmouseover= "Localurlmanage.setclipvalue (This, ' #copyUrlValue <% #Eval (" Id ")%> ')" > click Copy </button>

Copy Code code 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. Set the hidden Flash container to be left,top by dynamically binding the event on each copy button and after the value of the response is passed to the function, or after the control passes to it. Let it float on the button that triggers the event and pass the value you want to copy
Clip.settext (' text ') (provided by the plugin) is passed to flash so that multiple button copying functions are implemented
Did not solve the problem, the original button had to hovercss switch effect after flash cover is not very flexible. Adding a style dynamically with jquery is not a good result.

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.