Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript: document.execCommand cross-browser?

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.

like image 340
jldupont Avatar asked Nov 30 '09 01:11

jldupont


People also ask

Is document execCommand deprecated?

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.

Can I use document execCommand?

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.


1 Answers

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.

like image 186
peller Avatar answered Oct 19 '22 22:10

peller