Frames object (Object/browser)

A collection of frames belonging to a document or window.


JavaScript - 1.0
JScript - 1.0
Internet Explorer - 3.02
Netscape - 2.0
Opera - 3.0
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.


Example code:

   // 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];
   // Select genuine frame objects
   function isDesiredFrameObject(aProperty, anObject)
      if(toString(anObject) == "[object Window]")
            case "frames" :
            case "parent" :
            case "top"    :
            case "self"   :
               return false;
            default       :
               return true;
      return false;

See also:Collection object, Document.frames[], Frame object, Window object, Window.frames[]

length1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.0 n/a n/a n/a n/a n/areadonly

item()1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.0 n/a n/a n/a n/a n/aWarning