How to copy to clipboard with GWT?

后端 未结 6 2083
面向向阳花
面向向阳花 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:30

    GWT doesn't natively support the $doc.execCommand('copy'); command, but it's super easy.

    First set the focus on the item, select the text, then copy it.

    myTextBox.setFocus(true);
    myTextBox.selectAll();
    boolean success = copyToClipboard();
    
    private static native boolean copyToClipboard() /*-{
        return $doc.execCommand('copy');
    }-*/;
    

提交回复
热议问题