8. Built-In Methods
Some of these methods are attached to the lowest level objects window and document including for example the document.write() method which we have seen several times to this point.
Some of these methods, alert(), confirm() and prompt() are not attached to any specific object.
This section formally reviews these I/O methods as well as adding a couple of new tools: window.open() and document.getElementById()
8.1 Generic Methods
As was show in several previous examples, these methods are invoked as bareword function names to the following results:
The alert() method opens a dialog box including a single [OK] button and prints the contents of a message, [message] designated by the developer:
The alert() method has no result or return value.
The confirm() method opens a dialog box including a pair of [Cancel] and [OK] buttons and prints the contents of a message, [message] designated by the developer:
The confirm() method returns of true or false depending on the dialog button selected by the user: [OK] => true; [Cancel] => false.
The prompt() method opens a dialog box including a pair of [Cancel] and [OK] buttons and a single line text input, and prints the contents of a message, [message] designated by the developer:
The prompt() method returns one of several possible values:
First, if the user selects [Cancel], the result is false.
Second, if the user enters no text in the input but clicks [OK], the result is null and/or false.
Third, if the user enters some text in the input and clicks [OK], the result is value of the input contents and/or true.
8.2 Document Methods
The document.write() method prints the value of [contents] as inline html/text content:
Note that, subject to certain security restrictions, the document can be a document open in a window (or frame) other than the current window (see window.open() below).
The document.writeln() method prints the value of [contents] as inline html/text content followed by a newline (\n | \r) character
Note that if the contents of [contents] is HTML this will result in a displayed space as opposed to a hard return (<br />)
The document.close() method closes the body of the document to further inline input.
Subsequent document.write() commands will clear the current displayed contents of the document and begin a fresh <body> element.
This behavior is useful primarily when writing to a document open in other than the current window.
8.3 Window Methods
8.3.1 Window Open
8.3.2 Window Close
Part 8 of 9 | Next Part 9: Built-in Arrays >