Read clipboard data with GWT [duplicate]

痞子三分冷 提交于 2019-12-20 03:52:08

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!