Copy to Clipboard in GWT js+flash replication compatibility better _javascript skills

Source: Internet
Author: User

But you can copy it with Flash. The example is VERYCD, see the "Copy Selected Connection" button is a flash. It appears that Flash's security sandbox has no restrictions on copying content to the Clipboard

But there are limits:

1 According to Zeroclipborad, these flash must be loaded over the network.

Zero Clipboard does not Work to local Disk


This is a security restriction by Adobe Flash Player. Unfortunately, since we are utilizing the Javascript-to-flash interface ("externalinterface") this Only works as 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 your 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 the 'zeroclipboard.swf' file to the Trusted files list, or try the ' Allow all ' option.


2 Flash provides a copy function, but only if the user clicks on it. Meaning is not in JavaScript through the way of function SetText copied to the clipboard, but called the SetText function, the user's mouse in Flash has a click, can.

This is fully compatible with Flash Player, which requires that clipboard copy operation to initiated by a User Click event inside the Flash movie.

This is the same problem with swfupload uploading files using Flash.


With Zeroclipboard, you can copy the contents of a Web page to the Clipboard. But Zeroclipboard does not have a GWT package, our project is in GWT, so we learn the SWFUpload GWT package and encapsulate Zeroclipboard as a form that GWT can call.

1 first encapsulates a zeroclipboard.jar.

The 2 project uses the GXT Control Library, in order to tightly combine with the control, write a Zclipboardbinder class, combine the two

3 Use method see below (Zeroclipboard_test.java)

Copy Code code 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 define <code>onmoduleload () </code>.
*/
public class Zeroclipboard_test implements EntryPoint {
public void Onmoduleload () {
Layoutcontainer C = new Layoutcontainer ();
C.setsize (400, 300);
Button btn = New button ("Copy Hello World");
binding Controls and 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);
}
}

Related downloads are in the attachment.

Attachment.zip

Schematic result


Click on the button--in fact, click on the flash above, using CTRL + V, you can see the results.


Now found that there are a lot of meaningful features can not be implemented in JavaScript, such as multiple file upload and copy to the Clipboard, are through a flash intermediary, "curve" to achieve, do not know the last HTML5 have not solved these problems, do not let us take a ride around.
Zero Clipboard Open Source Javascript+flash Replication Library class

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.