11.12.2012 Views

JavaScript 2.0-The Complete Reference, Second ... - freecodingtutorial

JavaScript 2.0-The Complete Reference, Second ... - freecodingtutorial

JavaScript 2.0-The Complete Reference, Second ... - freecodingtutorial

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Table 13-2: Traditional Document Collections<br />

Collection<br />

Name<br />

Description Browser<br />

Compatibility<br />

applets[] All the Java applets in a page<br />

as defined by the tag.<br />

embeds[] All the tags in a<br />

page.<br />

forms[] All forms in a page as set by<br />

the tag.<br />

images[] A collection of all images in the<br />

page indicated by the HTML<br />

tag.<br />

links[] <strong>The</strong> links in the page defined<br />

by tags of the form ….<br />

plugins[] All the tags in a<br />

page. This collection is<br />

synonymous with embeds[],<br />

the preferred collection.<br />

Netscape 3+<br />

and Internet<br />

Explorer 4+<br />

Netscape 3+<br />

and Internet<br />

Explorer 4+<br />

Netscape 2+<br />

and Internet<br />

Explorer 3+<br />

Netscape 3+<br />

and Internet<br />

Explorer 4+<br />

Netscape 2+<br />

and Internet<br />

Explorer 3+<br />

Netscape 3+<br />

and Internet<br />

Explorer 4+<br />

DOM<br />

Support<br />

DOM Level 1<br />

No DOM<br />

Support<br />

DOM Level 1<br />

DOM Level 1<br />

DOM Level 1<br />

No DOM<br />

support<br />

Besides the common collections presented in Table 13-2, traditionally the Document object<br />

also has supported the title property, which holds the title of the document as specified by the<br />

tag within the head element of an (X)HTML document. Under traditional <strong>JavaScript</strong>,<br />

this property is a read-only string. However, under modern browsers you can set its value as<br />

well.<br />

document.anchors[] and document.links[]<br />

<strong>The</strong> first (X)HTML tag-related objects we examine in detail are links and anchors that have<br />

been accessible since the first versions of <strong>JavaScript</strong>. In (X)HTML, an anchor is a link that is<br />

named—in other words, it serves as a destination for other links. Anchors are defined with …. A link is also defined with the tag but contains an<br />

href attribute setting a link destination, like so: click<br />

me!. Of course, it should be evident that a link can be an anchor as well, since is perfectly valid.<br />

<strong>The</strong> anchors[] collection doesn‘t seem too useful in <strong>JavaScript</strong> because traditionally you could<br />

only access its length property using document.anchors.length. Other than that you really<br />

can‘t appear to modify anything. Since under the DOM an tag is referenced by an<br />

HTMLAnchorElement, you are certainly free to change an arbitary attribute of the tag.<br />

<strong>The</strong> links[] collection contains all the objects corresponding to each found in the<br />

document. As it is an array we can, of course, access its length with document.links.length.<br />

However, we can manipulate the URLs within the href attributes of each link. Link objects<br />

under most browsers will have the same properties as the Location object, including hash,<br />

host, hostname, href, pathname, port, protocol, and search. <strong>The</strong>se properties correspond<br />

to the individual portions of a URL except href, which contains the whole URL.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!