Availability: |
| ||||||
JavaScript syntax: | - | myFrames = frames | |||||
- | myFrames = myDocument.frames | ||||||
- | myFrames = myWindow.frames | ||||||
Object properties: | length | ||||||
Object methods: | item() |
An array of Frame objects contained within the document or window.
If the Frames object were named consistent, with the rest of MSIE, it might be called a FrameArray object.
Note that Frame objects is really another name for Window objects.
Each entry in the Frames object is a reference to a Window object for the specified frame.
Giving the individual frames a name with the NAME="..." HTML tag attribute does not feed through into the Frames array. The entries are simply numbered with their index value.
The frames property in Netscape points at a Window object rather than a Frames object. Although there is no Frames array in Netscape, the Window object acquires a length value which is the number of Frame objects. However, the frames are not enumerable by index number. We can simulate the functionality of the Frames array but to do this, we will need to enumerate all the properties of the Window object and eliminate the ones we don't want.
The example below illustrates how to enumerate through the properties of a Window object and extract only those which are valid Frame objects. The toString function forces the new array to pose as a new object class. This actually works in MSIE and Netscape and yields an array that is consistent in both browsers.
The frames property in MSIE points at a FramesArray object that is easy to enumerate and operate on by itself. In Netscape, the properties that would have been stored in the FramesArray in MSIE are simply dumped into the global property space, and stored in a Window object. This not only makes them harder to find but much harder to operate on in a logical way. Yet again it illustrates the need for script developers to be aware of the finer points regarding the differences between MSIE and Netscape.
// Build a FrameArray in Netscape var myIndex = 0; var myFramesArray = new Array(); myFramesArray.toString = function () { return "[object FrameArray]"; } for(var myProp in frames) { if(isDesiredFrameObject(myProp, frames[myProp])) { myFramesArray[myIndex] = frames[myProp]; myIndex++; } } // Select genuine frame objects function isDesiredFrameObject(aProperty, anObject) { if(toString(anObject) == "[object Window]") { switch(aProperty) { case "frames" : case "parent" : case "top" : case "self" : return false; default : return true; } } return false; }
Property | JavaScript | JScript | N | IE | Opera | NES | ECMA | DOM | CSS | HTML | Notes |
---|---|---|---|---|---|---|---|---|---|---|---|
length | 1.0 ![]() | 1.0 ![]() | 2.0 ![]() | 3.02 ![]() | 3.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | readonly |
Prev | Home | Next |
frameRate | Up | Frames.length |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. |