Use JavaScript framework
When talking about the window object, we mentioned that a web page within a frame is also a window object, that is to say, a Frame object is also a window object. In the simplest terms, each HTML file occupies a window object, including the web page that defines the frame (the "frame page"). In IE, the frame inserted into the document using the "
If the window object specified using window.frameName is also a frame web page, then the method of referencing its frame: window.frameName.subFrameName. And so on.
It should be noted that no matter where the "window" object is referenced, what is returned is the "current" window object. If you want to access other window objects, you need to use the parent and top attributes. parent refers to the "parent" window object, which is the frame web page containing the current window object; top refers to the window object at the top of the window.
When using frameworks, you also need to pay close attention to the global variables and custom functions defined in your JavaScript. They all have their own window object. To reference global variables or custom functions in other frameworks, you have to use the annoying method of "window object.frame object[.frame object...].global variables or custom functions".
The above problem is often ignored when establishing a connection: If a default target window (
Frame Programming Overview
An HTML page can have one or more sub-frames, which are marked with
1. Reference from parent frame to child frame
Knowing the above principles, it becomes very easy to reference child frames from parent frame, that is: 2. Reference from child frame to parent frame
Each window object has a parent attribute that represents its parent frame. If the frame is already a top-level frame, window.parent also represents the frame itself.
3. References between sibling frames
If two frames are sub-frames of the same frame, they are called sibling frames. They can reference each other through the parent frame. For example, a page includes 2 sub-frames:
Change the loading page of the frame
A reference to a frame is a reference to the window object. Using the location attribute of the window object, you can change the navigation of the frame, for example:
Referencing JavaScript variables and functions in other frameworks
Referring to JavaScript variables and functions in other frameworks Before the function technology, let’s take a look at the following code:
window.frames["frameName"];
window.frames.frameName
window.frames[index]
Among them, the word window can also be replaced or omitted with self, assuming frameName is The first frame in the page, the following writing is equivalent:
self.frames["frameName"]
self.frames[0]
frames[0]
frameName
Each frame corresponds to an HTML page, so This frame is also an independent browser window, which has all the properties of a window. The so-called reference to the frame is also a reference to the window object. With this window object, you can easily operate the pages in it, such as using the window.document object to write data to the page, using the window.location property to change the page in the frame, etc.
The following introduces the mutual references between different levels of frames:
window.frames["frameName"];
In this way, the sub-frame named frameName in the page is referenced. If you want to reference a subframe within a subframe, according to the nature of the window object, the referenced frame can be implemented like this:
window.frames["frameName"].frames["frameName2"];
In this way, the second-level subframe is referenced Frames, and so on, can realize the reference of multi-layer frames.