Editing Methods
Editing functionality is applied to selected page content through scripts that apply the document.execCommand() method. Parameters are passed to this method giving the edit command to apply. The general format for the execCommand() method is shown below. It is applied through the document object.
document.execCommand("command" [,0] [,"value"])
|
<button title="Bold"
onclick="document.execCommand('Bold')">
<img src="Bold.gif"/>
</button>
Editing Commands
All of the available editing commands are too numerous to list here. The following table gives a sampling of what types of editing can be applied to selected text a page.
| Command | Description |
|---|---|
document.execCommand(“BackColor“,0,”color“) |
Sets the background color of the selected element; color is a color name or hexadecimal value. |
document.execCommand(“Bold“) |
Sets the current selection to bold style. |
document.execCommand(“Copy“) |
Copies the current selection to the clipboard. |
document.execCommand(“CreateLink“) |
Displays a dialogue box for entering a URL which is applied to the selected text. |
document.execCommand(“Cut“) |
Cuts the current selection to the clipboard. |
document.execCommand(“Delete“) |
Deletes the current selection. |
document.execCommand(“FontName“,0,”name“) |
Sets the font face of the current selection; name is a font name. |
document.execCommand(“FontSize“,0,”size“) |
Sets the font size of the current selection; size is an integer from 1 (smallest) to 7 (largest). |
document.execCommand(“ForeColor“,0,”color“) |
Sets the text (foreground) color of the selected element; color is a color name or hexadecimal value. |
document.execCommand(“Indent“) |
Increases the indent of the selected text by one indentation increment. |
document.execCommand(“InsertImage“,1) |
Displays a dialogue box for selecting and positioning a graphic image. |
document.execCommand(“InsertMarquee“) |
Inserts an empty marquee for entering displayed text. |
document.execCommand(“InsertOrderedList“) |
Formats an ordered list of current selection. |
document.execCommand(“InsertUnorderedList“) |
Formats an unordered list of current selection. |
document.execCommand(“Italic“) |
Sets the current selection to italic style. |
document.execCommand(“JustifyCenter“) |
Centers the text block in which the current selection is located. |
document.execCommand(“JustifyFull“) |
Justifies the text block in which the current selection is located. |
document.execCommand(“JustifyLeft“) |
Left justifies the text block in which the current selection is located. |
document.execCommand(“JustifyRight“) |
Right justifies the text block in which the current selection is located. |
document.execCommand(“Outdent“) |
Decreases the indent of the selected text by one indentation increment. |
document.execCommand(“Paste“) |
Pastes the current clipboard contents to current selection. |
document.execCommand(“Print“) |
Opens the print dialog box so the user can print the current page. |
document.execCommand(“RemoveFormat“) |
Removes all formatting from current selection. |
document.execCommand(“SelectAll“) |
Selects the entire document. |
document.execCommand(“StrikeThrough“) |
Sets the current selection to strike-through style. |
document.execCommand(“Subscript“) |
Sets the current selection to subscript style. |
document.execCommand(“Superscript“) |
Sets the current selection to superscript style. |
document.execCommand(“Underline“) |
Sets the current selection to underline style. |
document.execCommand(“Unlink“) |
Removes any hyperlink from the current selection. |
document.execCommand(“Unselect“) |
Clears the current selection. |