问题
I have this code that I have made to handle the CTRL+V from the browser, works fine however I need to get the clipboard data like this:
Event.addNativePreviewHandler(new Event.NativePreviewHandler() {
@Override
public void onPreviewNativeEvent(Event.NativePreviewEvent event)
{
NativeEvent ne = event.getNativeEvent();
// When CTRL + V is pressed
if (event.getNativeEvent().getKeyCode() == 86 && // 'V'
event.getNativeEvent().getCtrlKey() == true) {
// need to get the clipboard data
}
}
});
回答1:
Although I'm the one that marked this question as a duplicate, I think the answers in that question may be bit out of date. When I google, I find this discussion. The answers in there solve the problem with JSNI but they remark that it doesn't work in FF because FF requires manually enabling restrictions. If this doesn't help, you may have to use the answers in the duplicate.
回答2:
JavaScript per se does not allow to simply read the system clipboard as this would be a huge security risk. Most browsers do, however, provide the means to achieve this (although it has to be enabled by the user). The API is, thus, browser dependend. For Firefox have a look at https://developer.mozilla.org/en-US/docs/Using_the_Clipboard.
To the best of my knowledge there is na GWT specific wrapper of this functionality. Thus, you need to work with GWT JSNI (http://www.gwtproject.org/doc/latest/DevGuideCodingBasicsJSNI.html)
来源:https://stackoverflow.com/questions/18599156/read-clipboard-data-with-gwt