I just stumble on a piece of code which I never saw before:
document.execCommand('Copy');
which seems to copy the clipboard contents to the element in focus.
Is this functionality available cross-browser?
I found a page that shows a compatibility matrix for document.execCommand
.
Year 2022 answer: The execCommand() is officially obsolete/deprecated but there's no alternative. So if you must have rich text support, you have to keep using execCommand() and figure out yourself what actually works with browsers that you want to support.
execCommand() Deprecated: This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes.
This is for 'design mode' where the browser effectively turns the document into an editor. The execCommand API originated with IE and was later added to HTML5. Exactly which commands are supported, as well as their behavior varies across browsers. Clipboard access is considered a security risk.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With