Document.execCommand() (Method)

Part of an MSIE special document command handling mechanism. A method for executing commands.

Availability:

JScript - 3.0
Internet Explorer - 4.0
Property/method value type:Boolean primitive
JavaScript syntax:IEmyDocument.execCommand(aCommand)
IEmyDocument.execCommand(aCommand, aUIFlag)
IEmyDocument.execCommand(aCommand, aUIFlag, aParameter)
Argument list:aCommandAn MSIE command to execute
aParameterParameter value to the command
aUIFlagDisplay or inhibit UI appearance

The MSIE browser supports a special command handling interface that hooks through the browser's user interface. It allows you to automate user actions in a way that other browsers and non-Windows platform users cannot take advantage of.

Although this is a method that applies to a document object, many of the commands that are executed through this mechanism will require that a TextRange object is created and available first.

The result returned by this method, is a Boolean true if the action succeeded, and a Boolean false if it failed in someway.

The flag parameter provides a way to suppress any user interface changes that may appear as a result of executing the command.

NameDescription
2D-PositionAbsolutely positioned elements can be moved by dragging.
AbsolutePositionSets an element's position property to "absolute"
BackColorThe background color for the current selection is set to the color value passed in the parameter argument.
BoldThe selected text has <B> and </B> tags placed at either end.
CopyThe TextRange is copied to the clipboard.
CreateBookmarkCarries out modifications to an existing <A> tag or creates one, then adds the item to the bookmarks list. The parameter provides the NAME value. The <A> tag is removed if there is no parameter.
CreateLinkWraps an <A HREF="..."> tag around the selected text. The parameter contains the URL value for the HREF.
CutPerforms a cut to clipboard.
DeleteThe text range is deleted. This is not the same as a Cut command.
FontNameWraps <FONT> tags round the selection. The required font face is passed in the parameter.
FontSizeWraps <FONT> tags round the selection and defines the fonts size from the parameter value.
ForeColorRedefines the foreground btext color for the selection taking the color value from the parameter.
FormatBlockWraps a <BLOCK> tag round the TextRange.
IndentThe TextRange is indented
InsertButtonA <BUTTON> tag is placed at the current insertion point in the document. Its ID value is defined by the parameter.
InsertFieldsetA <FIELDSET> tag is inserted with theID value being taken from the parameter
InsertHorizontalRuleAn <HR> tag is added at the current insertion point.
InsertIFrameA new <IFRAME> is inserted with the content URL being provided in the parameter.
InsertImageOverwrites an image on the current selection.
InsertInputButtonAn <INPUT TYPE="Button"> is added with its ID value coming from the parameter.
InsertInputCheckboxAn <INPUT TYPE="Checkbox"> is added with its ID value coming from the parameter.
InsertInputFileUploadAn <INPUT TYPE="FileUpload"> is added with its ID value coming from the parameter.
InsertInputHiddenAn <INPUT TYPE="Hidden"> is added with its ID value coming from the parameter.
InsertInputImageAn <INPUT TYPE="Image"> is added with its ID value coming from the parameter.
InsertInputPasswordAn <INPUT TYPE="Password"> is added with its ID value coming from the parameter.
InsertInputRadioAn <INPUT TYPE="Radio"> is added with its ID value coming from the parameter.
InsertInputResetAn <INPUT TYPE="Reset"> is added with itsID value coming from the parameter.
InsertInputSubmitAn <INPUT TYPE="Submit"> is added with itsID value coming from the parameter.
InsertInputTextAn <INPUT TYPE="Text"> is added with its ID value coming from the parameter.
InsertMarqueeA new <MARQUEE> is added with the ID being taken from the parameter.
InsertOrderedListA new <OL> is added with the ID being taken from the parameter.
InsertParagraphA new <P> is added with the ID being taken from the parameter.
InsertSelectDropdownA new <SELECT TYPE="select-one"> is added with the ID being taken from the parameter.
InsertSelectListboxA new <SELECT TYPE="select-multiple"> is added with the ID being taken from the parameter.
InsertTextAreaA new <TEXTAREA> is added with the ID being taken from the parameter.
InsertUnordredListA new <UL> is added with the ID being taken from the parameter.
ItalicThe TextRange is enclosed with <I> tags.
JustifyCenterThe TextRange is centered within its parent object.
JustifyFullThe TextRange is fully justified.
JustifyLeftThe TextRange is left justified.
JustifyRightThe TextRange is right justified.
LiveResizeCauses the MSHTML Editor to update an element's appearance continuously during a resizing or moving operation, rather than updating only at the completion of the move or resize.
MultipleSelectionAllows for the selection of more than one site selectable element at a time when the user holds down the SHIFT or CTRL keys.
OutdentThe complement of the Indent command.
OverWriteThe input-typing mode is set to overwrite if the parameter value is true and insert if it is false.
PasteThe contents of the clipboard are pasted into the TextRange.
PlayImageIf an image represents a video clip, then it starts playing.
RefreshThe document is reloaded.
RemoveFormatThe complement of the FormatBlock command.
SaveAsSaves the current Web page to a file.
SelectAllThe entire document text is selected.
StopImageThe complement of the PlayImage command.
UnBookmarkThe complement of the CreateBookmark command.
UnderlinePlaces <U> tags around the TextRange.
UnlinkThe complement of the CreateLink command.
UnselectUnselects whatever was selected to create the TextRange. Many commands are now inappropriate until a new TextRange has been created.

None of these commands provide any greatly significant functionality as far as dynamic HTML is concerned. A few of them allow you to manage the clipboard and bookmark lists. It is probably best to avoid using these commands and use the more usual ways of accessing the document internals.

Warnings:

See also:Document object, Document.queryCommandEnabled(), Document.queryCommandIndeterm(), Document.queryCommandState(), Document.queryCommandSupported(), Document.queryCommandText(), Document.queryCommandValue(), FileUpload.select(), TextRange.execCommand()