Home >Web Front-end >JS Tutorial >Copy to clipboard in GWT js flash implements copying with better compatibility_javascript skills

Copy to clipboard in GWT js flash implements copying with better compatibility_javascript skills

WBOY
WBOYOriginal
2016-05-16 18:33:051310browse

But you can copy it using flash. An example is VeryCd. Look at the "Copy selected connection" button which is a flash. It seems that flash’s security sandbox does not restrict copying content to the clipboard

But there are limitations:

1 According to the folks at ZeroClipborad, these flashes must be loaded over the network.

Zero Clipboard Does Not Work From 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 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 a copy function, it only requires one click from the user. This means that you cannot copy to the clipboard through the setText function in JavaScript. Instead, after calling the setText function, the user's mouse clicks on the 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 has the same problem as swfupload that uses flash to upload files.


Using ZeroClipboard, you can copy web content to the clipboard. However, ZeroClipboard does not have GWT encapsulation. Our project uses GWT, so we learned from swfupload's GWT encapsulation and encapsulated ZeroClipboard into a form that can be called by GWT.

1 First encapsulate a zeroclipboard.jar

2 The GXT control library is used in the project. In order to closely integrate with the control, I wrote a ZClipboardBinder class to combine the two

3 The usage method is shown below (Zeroclipboard_test.java)

Copy the code 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 define onModuleLoad().
*/
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);
}
}

Relevant downloads are in the attachment.

attachment.zip

Showing the result


After clicking the button - you actually clicked on the flash above. Use ctrl v to see the result.


Now I find that there are many meaningful functions that cannot be implemented with JavaScript, such as uploading multiple files and copying to the clipboard, which are all implemented through flash as an intermediary and "curve". I don't know the final HTML5 There is no need for us to dwell on whether these problems have been solved.
Zero Clipboard open source JavaScript flash copy library class

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn