Copy to clipboard in GWT js + flash for better replication compatibility _ javascript skills

Source: Internet
Author: User
Today, we see a GoogleCode project called ZeroClipboard. The idea is to copy the content to the clipboard using flash as a media. This is better than using javascript, because different browsers have different responses for security reasons. For example, IE will prompt that some Browsers Do not support copying to the clipboard. However, you can copy the data in flash. The example is VeryCd. The "Copy selected connection" button is a flash. It seems that the flash Security Sandbox has no limit on copying content to the clipboard.

However, there are limits:

1 According to ZeroClipborad, these flash files must be loaded through the network.

Zero Clipboard Does Not Work From Local Disk


This is a security restriction by Adobe Flash Player. Unfortunately, since we are utilizingJavaScript-to-FlashInterface ("ExternalInterface") This only works while truly online (if the page URL starts with" http: // "or" https ://"). it won't work running from a local file on disk.

However, there is a way for you to edit your local Flash Player security settings and allow this. Go to this website:

Http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04a.html

And add the path to your local"ZeroClipboard.swf"File to the trusted files list, or try the" allow all "option.


2. Although flash provides the copy function, the premise is that you can click it once. This means that the setText function cannot be used in javascript to copy to the clipboard. Instead, after the setText function is called, the user's mouse can be clicked on flash.

This library is fully compatible with Flash Player 10, which requires that the clipboard copy operation be initiated by a user click event inside the Flash movie.

This is the same as the swfupload for uploading files using flash.


With ZeroClipboard, you can copy the webpage content to the clipboard. However, ZeroClipboard does not have GWT encapsulation. Therefore, we use GWT for our projects. Therefore, we learn how to use swfupload GWT encapsulation to encapsulate ZeroClipboard into a form that GWT can call.

1 first encapsulates a zeroclipboard. jar

2. The GXT control library is used in the project. To work closely with the control, a ZClipboardBinder class is written to combine the two.

3. for usage instructions, see Zeroclipboard_test.java)

The Code is as follows:


Package zero. clipboard. test. client;
Import java. util. Date;
Import zero. clipboard. test. client. ZClipboardBinder. ClipboardListener;
Import com. extjs. gxt. ui. client. widget. LayoutContainer;
Import com. extjs. gxt. ui. client. widget. button. Button;
Import com. google. gwt. core. client. EntryPoint;
Import com. google. gwt. user. client. ui. RootPanel;
/**
* Entry point classes defineonModuleLoad().
*/
Public class Zeroclipboard_test implements EntryPoint {
Public void onModuleLoad (){
LayoutContainer c = new LayoutContainer ();
C. setSize (400,300 );
Button btn = new Button ("Copy Hello World ");
// Bind the control to ZeroClipboard
// ZClipboardBinder. bind (btn, "Hello World ");
ZClipboardBinder. bind (btn, new ClipboardListener (){
@ Override
Public String prepareCopy (){
Return (new Date (). toString ();
}
});
C. add (btn );
RootPanel. get (). add (c );
}
}


The related downloads are all in the attachment.

Attachment.zip

Result


Click the button-click the flash above and press ctrl + v to see the result.


Now we find that many meaningful functions cannot be implemented using javascript. For example, uploading and copying multiple files to the clipboard are all implemented through flash as an intermediary and "curve, I don't know if HTML5 has solved these problems. We don't have to go around.
Zero Clipboard open-source JavaScript + flash Copy Library Class

Related Article

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.