22.1. Built-in JavaScript Objects

As previously mentioned, JavaScript's ability to access a document's structure and elements is perhaps the greatest advantage of using the language. Besides being able to access the Document Object Model (discussed in depth in Chapter 21), JavaScript also has a host of built-in objects that can be used to access the user agent and the document it contains. This section introduces the various objects and how JavaScript can use them.

For in-depth listings of all built-in objects, properties, and methods, see Appendix C. For more examples of how to use JavaScript for Dynamic HTML, see Chapter 23.

22.1.1. Window Object

The window object is the top-level object for an XHTML document. It includes properties and methods to manipulate the user agent window. The window object is also the top-level object for most other objects.

Using the window object, you can not only work with the current user agent window, but you can also open and work with new windows. The following code will open a new window displaying a specific document:

NewWin = window.open("example.htm","newWindow",
  "width=400,height=400,scrollbars=no,resizable=no");

The open method takes three arguments: a URL of the document to open in the window, the name of the new window, and options for the window. For example, the preceding code opens a window named newWindow containing the document example.htm and will be 400 pixels square, be nonresizable, and have no scrollbars.

The options supported ...

Get Web Standards Programmer's Reference: HTML, CSS, JavaScript®, Perl, Python®, and PHP now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.