Javascript: document.execCommand cross-browser?

jldupont picture jldupont · Nov 30, 2009 · Viewed 76.1k times · Source

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.

Answer

peller picture peller · Nov 30, 2009

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.