HTML and CSS Reference
In-Depth Information
be used to gain programmatic access to the page's elements, attributes, and text. What
was also mentioned is that the DOM is accessible through a document object, which
is contained inside another object—the window object. What wasn't mentioned is that
more abstract entities (besides the web page document) can be accessed through the
window object. For example, there is programmatic access available to the browsing
history, website URL location, screen dimensions, and so forth. Each of these entities is
accessible through the window as an object in its own right.
So, what exactly are objects? Objects are merely a collection of properties and meth-
ods . What does that mean? Properties are a series of keys and values, like attributes on
HTML elements. They are what an object has . For instance, the width of the screen is
a property that holds a specific value (the screen width in pixels). Some properties are
read-only, while others can have their values overwritten. Properties are also known as
variables, depending on the context.
Methods describe what a particular object can do . For instance, using JavaScript to
pop up an alert window is done through a method. Methods are also known as func-
tions . They are self-contained blocks of code that will run only when called, like the
function you saw in the template JavaScript code in the previous section.
For instance, the window object has a property called name that can be used to add
an identifier to a particular web browser window. 1 This property is not read-only, so it
can be read and written to.
As far as methods go, the window object has a method (among many) called
alert() , which you've likely seen in use. It pops up a dialog box with a message and
an OK button. Using dot notation (described in Chapter 1), these could both be used like
1 This may be used in the target attribute of hyperlinks in order to open a linked resource in a spe-
cific windows
function init() {
// sets the name of the window = "MAIN";
// shows the name of the window
window.alert("The name of this window is set to: "
window.onload = init;
Search WWH ::

Custom Search