How to copy to clipboard with GWT?

后端 未结 6 2055
面向向阳花
面向向阳花 2020-12-17 14:56

Couldn\'t find anything on this with a Google Search.

Does anyone know how to copy some text to the clipboard through GWT Java code? I\'d like to avoid the raw javas

6条回答
  •  独厮守ぢ
    2020-12-17 15:10

    The following code worked fine for me in chrome:

    public static native void copyToClipboard() /*-{
        var selection = $wnd.getSelection();
        var text =  $doc.getElementById("myElement");
        var range = $doc.createRange();
        range.selectNodeContents(text);
        selection.removeAllRanges();
        selection.addRange(range);
        $doc.execCommand('copy');
        selection.removeAllRanges();
    }-*/;
    

提交回复
热议问题