15.02.2013 Views

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

136<br />

<strong>JavaScript</strong> <strong>Examples</strong> <strong>Bible</strong>: The Essential Companion to <strong>JavaScript</strong> <strong>Bible</strong><br />

In the next example, the user is asked to approve the addition of a URL to the<br />

Favorites list. The user can follow the normal procedure for filing the item in a<br />

folder in the list.<br />

external.AddFavorite(“http://www.dannyg.com/update6.html”,<br />

“JS<strong>Bible</strong> 4 Support Center”)<br />

The final example assumes that a user makes a choice from a SELECT list of items.<br />

The onChange event handler of the SELECT list invokes the following function to navigate<br />

to a fictitious page and locate listings for a chosen sports team on the page.<br />

function locate(list) {<br />

var choice = list.options[list.selectedIndex].value<br />

external.NavigateAndFind(“http://www.collegesports.net/scores.html”, choice,<br />

“scores”)<br />

}<br />

frames<br />

windowObject.frames<br />

NN2 NN3 NN4 NN6 IE3/J1 IE3/J2 IE4 IE5 IE5.5<br />

Compatibility ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓<br />

Example<br />

Listings 16-7 and 16-8 demonstrate how <strong>JavaScript</strong> treats values of frame references<br />

from objects inside a frame. The same document is loaded into each frame. A<br />

script in that document extracts info about the current frame and the entire frameset.<br />

Figure 2-1 shows the results after loading the HTML document in Listing 16-7.<br />

Listing 16-7: Framesetting Document for Listing 16-8<br />

<br />

<br />

window.frames property<br />

<br />

<br />

<br />

<br />

<br />

<br />

A call to determine the number (length) of frames returns 0 from the point of<br />

view of the current frame referenced. That’s because each frame here is a window<br />

that has no nested frames within it. But add the parent property to the reference,<br />

and the scope zooms out to take into account all frames generated by the parent<br />

window’s document.

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

Saved successfully!

Ooh no, something went wrong!