In this hierarchy, the object's "descendants" are properties of the object.
For example, a form named
myform is an object as well as a property
document, and it is referred as
Every page has the following objects:
navigator: has properties for the version of Navigator being used, the MIME types supported and the plug-ins installed in the client.
window: has properties that apply to the whole window.
document: contains properties based on the content of the document, such as title, background color, links and forms.
location: has properties based on the current URL.
history: contains properties representing URLs the client has previously requested.
For example, to refer the
value property of a text field named
myform, the following syntax can be
Document properties are largely content-dependant. They are created based on the HTML in the document: for example, document has a property for each form and each anchor in the document. Some of the document objects can be changed, like a text field value or an image source. But others can only be reflected by their values, and cannot be changed, like the HTML page title.
The window object has some useful methods like:
close: Opens and closes browser window.
alert: Displays an Alert dialog box with a message.
confirm: Displays a Confirm dialog box with OK and Cancel buttons.
prompt: Displays a Prompt dialog box with a text field for entering a value.
scrollTo and scrollBy: scrolls a window to a specified coordinate or by a number of pixels.
setTimeout: Evaluates an expression or calls a function once after the specified period elapses.
It has also some properties you can set like
Two of the most important methods in the document object are write and writeln. These methods allow to write flexible HTML code inside the HTML document.The next example shows a way of personalizing a home page, depending on the visitor:
name=prompt("Please enter your name:","Anonymous");
The rest of the page.......
And this is the output
Each form of the document creates a
Form object. All
objects are stored in an array called
forms, and they
are referred in a document in two ways: by heir names or by their positions.
The elements in a form are also stored in an
and can be referred, as forms, by their names or positions. For example,
suppose you have the following HTML code:
<INPUT TYPE="text" NAME="text1" VALUE="Your Name">
<INPUT TYPE="button" NAME="button1" VALUE="Click Me!">
So referring to
document.forms is the same as referring
is the same as referring to
To create a window you should use the open method. The syntax for this method is:
window.open(URL, WindowName, WindowFeatures)
WindowFeatures are optional.
WindowFeatures is a string containing a comma-separated list
determining whether or not to create various standard window features. Some
of these features include window size, including or not toolbars, etc...
The following code creates a window called
menu with the contents
of the file
The next example opens a new window, size 300 by 200 pixels, and no menubar:
A second name can be given to a certain window. This way, we can select a window as a target window for more than one HTML document:
You can also create a document with the contents you want. The next example shows how to do it:
The close() method for the document object closes an output stream and forces data sent to layout to display.
To close a window, you should use the
close method. So, the
syntax used is:
To close the same window where the code is written, one of the following statements can be used:
To close the
menu window in the previous example, you should
use the syntax: