O'Reilly logo

Dynamic HTML: The Definitive Reference by Danny Goodman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Appendix D. Internet Explorer Commands

Internet Explorer 4 includes a set of commands that work directly with the document and (Win32 only) TextRange objects. In many cases, these commands mimic the functionality available through setting properties or invoking methods of the objects. Even so, these commands exist outside of the primary document object model and are therefore treated separately in this appendix.

Access to these commands is through a set of document and TextRangeobject methods that are described in Chapter 9. These commands and syntax are:

execCommand("commandName"[, UIFlag[, value]])
queryCommandEnabled("commandName")
queryCommandIndeterm("commandName")
queryCommandState("commandName")
queryCommandSupported("commandName")
queryCommandText("commandName")

This appendix focuses on the commands and values that may be applied to the execCommand() method (the commands may also be applied to the other methods).

Some commands work on the current selection in a document, which means that the selection must be made manually by the user or via a script and the Text-Range object. For example, the following function locates every instance of a string passed as a parameter and turns its text color to red:

function redden(txt) {
    var rng = document.body.createTextRange()
    for (var i = 0; rng.findText(txt) != false; i++) {
        rng.select()
        document.execCommand("ForeColor","false","red")    
        rng.collapse(false)
        rng.select()
    }
}

The process is iterative. After creating a text range for ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required