copy to clipboard?
Added by Mark Travis over 1 year ago
I've got a popup window that I've built some text in.
My user keeps fumbling the cut-and-paste of the text, so I'm looking for a way to automate copying this text to the clipboard.
Is there a way to do that through Wt? I tried a search for "clipboard" but didn't find anything. Maybe it's named something else, or maybe it doesn't exist?
Replies (2)
RE: copy to clipboard? - Added by Stefan Bn over 1 year ago
You can copy contents to the clipboard using the standard JavaScript function Clipboard.writeText()
, see here:
https://developer.mozilla.org/en-US/docs/Web/API/Clipboard/writeText
Just create a JavaScript function with all the necessary code and success/error handling in a separate .js-File. Include this .js-File to your WApplication using WApplication::require()
and call this method from your Wt code using WApplication::doJavascript()
.
Be aware that clipboard access is restricted and needs a secure context and this only works if your server is based on HTTPS or accessed at localhost, see here:
https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts
Best,
Stefan
RE: copy to clipboard? - Added by Mark Travis over 1 year ago
Thanks! I need to set up https. I'm getting close to having a commercial app available and that will be one of the first things I do. (After happily paying Emweb for a license, that is!)