HTML and CSS Reference
In-Depth Information
B.1.3. Editing API
The Editing API allows you to implement direct editing of HTML pages loaded in the
browser. This is commonly referred to as rich-text editing; it enables the web application to
use all the formatting options available to HTML. This ability distinguishes rich-text edit-
ing from plain-text editing that can be achieved in textarea elements and other form
inputs.
The Editing API was created by reverse engineering the behavior of IE. The documentation
had always been incomplete, so there are many parts of it that exist simply because IE has
them rather than because there's a rational explanation for their existence.
All the methods in table B.5 are on the document object; in most cases they will apply to
any selected block of text within a contenteditable section of the current document.
Table B.5. Editing API
Method
Description
Executes the command described in the first argument. The
command argument is a string value. The showUI argument
is a Boolean value to determine whether or not to show the
default UI associated with command. The value argument
is passed to command. Not all commands need a value ar-
gument.
execCommand(command, showUI, value)
queryCommandEnabled(command)
Checks if command is supported and enabled.
Checks if command is indeterminate (if the selected text is
part active and part inactive).
queryCommandIndeterm(command)
Returns a Boolean value indicating whether command is
currently applied to the selected text.
queryCommandState(command)
queryCommandSupported(command)
Checks if command is supported.
queryCommandValue(command)
Returns command's value, if it has one.
As you can see, the API isn't much use without a value to enter for command . Tables
B.6 - B.8 list categories of available commands. Pass the command as a string to the meth-
ods in table B.6 , for example: execCommand('bold',false,'' ). For more inform-
ation on these commands, see http://mng.bz/4216 .
Table B.6. Inline formatting commands
backColor
bold
createLink
fontName
fontSize
foreColor
 
 
Search WWH ::




Custom Search