execCommand compatibility

This table is under construction. Although most browsers support most basic functionalities, there may be implementation differences nonetheless.

For instance, when making a selection bold, IE and Opera add a <strong> tag, while Mozilla adds a <span style="font-weight: bold">. Safari's implementation is weird.

This page has been translated into Romanian.

Here you can follow my ongoing research of execCommand(). This method allows you to execute commands like Copy or Bold. All browsers support it, but obviously there are some differences.

On the whole Opera follows IE's implementation quite closely, while Mozilla and Safari have their own implementations.

See also my test page.

General notes

When changing the styles of an inline bit of text, Safari always applies a <span class="Apple-style-span"> to the block-level element that's the parent of the inline text, in addition to a span with the same class and the appropriate CSS declarations around the inline text itself.

For instance, suppose the user selects "bit of text" in this paragraph and makes it bold:

<p>This is a bit of text that the user selected.</p>

Safari generates this:

<p><span class="Apple-style-span">This is a
	<span class="Apple-style-span" style="font-weight: bold">bit of text</span>
	that the user selected</span>.</p>

The extra <span>, as well as the class name, are of course totally useless.

Bookmarks: http://www.bazon.net/mishoo/articles.epl?art_id=1292

Compatibility

Method or property Explorer 6/7 Firefox 2 Safari 3 Opera 9
backcolor
Yes Yes Yes Yes

Moz/Saf require the #. Moz/Op give bgcolor to block-level element selection is part of, IE/Saf to selection itself.
To get the IE/Saf effect in Moz, use hilitecolor.

bold
Yes Yes Yes Yes
Notes
contentReadOnly
No Yes ? No
IE gives error
copy
Yes Protected Yes Protected
Ctrl+C always works
createbookmark
? ? ? ?
Notes
createlink
Yes Yes Yes Yes
Notes
cut
Yes Protected Yes Protected
Ctrl+X always works
Method or property Explorer 6/7 Firefox 2 Safari 3 Opera 9
decreasefontsize
No Yes ? Incorrect
Op allows only 1 decrease; the 2nd reverts text to original font size.
delete
Yes Yes Yes Yes
Notes
fontname
Yes Yes Yes Yes
Notes
fontsize
No Horrid Yes Horrid

Moz/Op generate a (gulp!) <font> tag with size equal to parseInt(value). Saf creates a normal font-size CSS declaration.

forecolor
Yes Yes Yes Yes
Moz/Saf require #
formatblock
(put selection in header or paragraph)
No Yes Buggy Incomplete
Opera changes only the first block-level element in the selection to the desired block.
Method or property Explorer 6/7 Firefox 2 Safari 3 Opera 9
heading
No Yes No No
Notes
hilitecolor
No Yes No Yes

Does the same as bgcolor in IE/Saf: it gives only the selection (and not the containing block) the defined bgcolor.

increasefontsize
No Yes ? Incorrect
Op allows only 1 increase; the 2nd reverts text to original font size.
indent
Incorrect Yes Buggy More incorrect

Moz adds 40px of margin-left per indent. IE/Op add a (gulp!) blockquote for every indent.

When applied to an <li>, Moz/IE generate a nested <ol/ul>, but Op again inserts a <blockquote>.

inserthorizontalrule
Yes Yes Yes Yes
Notes
inserthtml
No Yes ? No
Notes
Method or property Explorer 6/7 Firefox 2 Safari 3 Opera 9
insertimage
Yes Yes Yes Yes
IE allows resizing of image
insertorderedlist
Almost Yes Almost Yes
If the newly created ordered list borders an existing list, IE and Safari merge the two.
insertunorderedlist
Almost Yes Yes Yes
If the newly created unordered list borders an existing list, IE merges the two.
insertparagraph
Yes Alternative Yes Yes
Mozilla adds a paragraph around the selected block. The other browsers delete the selected block and insert an empty paragraph which the user can fill.
italic
Yes Yes Yes Yes
Notes
justifycenter
Yes Yes Yes Yes
Notes
Method or property Explorer 6/7 Firefox 2 Safari 3 Opera 9
justifyfull
Yes Yes Yes Yes
Notes
justifyleft
Yes Yes Yes Yes
Notes
justifyright
Yes Yes Yes Yes
Notes
multipleselection
? ? ? ?
Notes
outdent
Yes Yes Buggy Yes

When applied to an <li> that's a child of a single <ol/ul>, Moz/IE move the <li> to outside the <ol/ul>, while Op doesn't react.

Unfortunately IE has an extra bug in my test page: it moves the <li> to entirely outside my test element.

overwrite
? ? ? ?
Notes
paste
Yes Protected Yes Protected
Ctrl+V always works
print
? ? ? ?
Notes
redo
Yes Yes Yes Yes
Redo works in Safari, but if you do Undo/Redo too often, it crashes. Solved in 3.
If you make your own changes in the editable area, Undo/Redo continues to work in Mozilla and Safari (though it ignores your custom changes), but in IE and Opera it stops working.
Method or property Explorer 6/7 Firefox 2 Safari 3 Opera 9
refresh
? ? ? ?
Notes
removeformat
? ? ? ?
Notes
saveas
? ? ? ?
Notes
selectall
? ? ? ?
Notes
strikethrough
Yes Yes Yes Yes
Notes
styleWithCSS
No Yes ? No
Gives a generic command that styles should be applied with CSS (true; default) or with tags (false). When doing execCommand("bold") the first would generate a <span style="font-weight: bold";>, the second a <b> tag.
subscript
Yes Yes Yes Yes
IE/Moz/Op: using the same command again removes the subscript. Using subscript and superscript together gives odd effects.
superscript
Yes Yes Yes Yes
IE/Moz/Op: using the same command again removes the superscript. Using subscript and superscript together gives odd effects.
Method or property Explorer 6/7 Firefox 2 Safari 3 Opera 9
unbookmark
? ? ? ?
Notes
underline
Yes Yes Yes Yes
Notes
undo
Yes Yes Yes Yes
Undo works in Safari, but if you do Undo/Redo too often, it crashes. Solved in 3.
If you make your own changes in the editable area, Undo/Redo continues to work in Mozilla and Safari (though it ignores your custom changes), but in IE and Opera it stops working.
unlink
Yes Yes Yes Yes
Notes
Method or property Explorer 6/7 Firefox 2 Safari 3 Opera 9