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 javascript injection solution.
Any help or pointers appreciated.
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 javascript injection solution.
Any help or pointers appreciated.
I have used ZeroClipboard with GWT (as suggested by Alexander) but it was not straightforward.
See http://blog.dandoy.org/2011/09/using-zeroclipboard-with-gwt.html
The following code worked fine for me in chrome:
Here a solution without native JS, but gwt elemental instead, still inspired by @SushmithaShenoy, leaving this here for future reference.
precondition:
now the 'real' code, maybe placed in a clickhandler:
For the moment it doesn't seem like there are any GWT libraries that provide this functionality. In any case, it's impossible to support this in all browsers as Flash is needed. A rather nice library than wraps the functionality is ZeroClipboard.
Just wrap the provided answer https://stackoverflow.com/a/30810322/106261.
So, you pass in any text to a javascript native function/method, the js function creates a new element and copies to clipboard, and removes the element after copying.
No need for any libs with new browsers.
so :
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.