18.04.2016 Views

Professional JavaScript For Web Developers

javascript for learners.

javascript for learners.

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

<strong>JavaScript</strong> in the Browser<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

This code creates a frameset with one frame across the top and two frames underneath. Here, the top<br />

frame can be referenced by window.frames[0] or window.frames[“topFrame”], however, you would<br />

probably use the top object instead of window to refer to these frames (making it top.frames[0], for<br />

instance).<br />

The top object always points to the very top (outermost) frame, which is the browser window itself. This<br />

assures that you are pointing to the correct frame. If you then write code within a frame, the window<br />

object referenced in it is a pointer to just that frame.<br />

Because the window object is the center of the BOM universe, it enjoys a special privilege: You don’t<br />

need to explicitly reference it. Whenever a function, object, or collection is referenced, the interpreter<br />

always looks to the window object, so window.frames[0] can be rewritten as just frames[0]. To<br />

understand the various ways to reference the frames in the previous example, refer to Figure 5-4.<br />

Figure 5-4<br />

It is also possible to access a frame directly using its name, such as window.leftFrame. However,<br />

using the frames collection is generally more acceptable because it more accurately represents the<br />

code’s intent.<br />

Another instance of the window object is called parent. The parent object is used with framesets that<br />

load files that are also framesets. Suppose the file named frameset1.htm contains this code:<br />

137

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

Saved successfully!

Ooh no, something went wrong!