JavaScript Framework programming 1th/2 Page _ Basics

Source: Internet
Author: User
Using the JavaScript framework
When we talk about the Window object, we mentioned that a Web page within a frame is also a Window object, that is, a frame object is also a Window object. The easiest thing to understand is that each HTML file occupies a window object, including a Web page that defines the frame ("frames page"). The frame that is inserted in the document with the "<iframe>" tag in IE is also a Window object, but the HTML read with the "Include Web Page" method (shown in HTML as "<!--WebBot bot=" include "...-->") Does not occupy the Window object alone. Each frame is a child of the Window object that contains its page (not known to be called "attribute"), and to reference it, you can use one of the following methods:
WINDOW.FRAMES[X]
window.frames[' FrameName ']
Window.framename

where x refers to the first frame specified in the Window object, and as with other arrays, X is zero-based. FrameName refers to the frame's name, which is the same as the "name" attribute in <frame>.

If the window object specified with Window.framename is a frames page, then the method that references its frame: Window.frameName.subFrameName. Analogy

When you want to be aware, wherever you refer to the "Window" object, the current Window object is returned. If you want to access other window objects, you need the parent and top properties. Parent refers to the Parental window object, which is the frames page containing the current Window object, and top refers to the window object that is topmost on the windows.

Use the framework to keep a close eye on global variables and custom functions defined in your JavaScript. They all have the window object that they belong to. To refer to a global variable or custom function in another frame, use the Window object. frame objects [. frame objects ...]. global variable or Custom function "this annoying method.

This problem is often ignored when establishing a connection: If a default target window (<base target= >) is defined in
Framework Programming Overview
An HTML page can have one or more child frames, which are marked with <iframe> to display a separate HTML page. Framework programming here includes the self-control of the framework and the mutual access between frameworks, such as referencing JavaScript variables from one frame to another, calling functions within other frameworks, controlling the behavior of forms in another frame, and so on.
Cross-references between frames
All frames in a page are provided as properties of the Window object in the form of a collection, for example: Window.frames represents a collection of all the frames within the page, similar to the form objects, linked objects, picture objects, and so on, and these collections are the properties of the document. Therefore, to refer to a child frame, you can use the following syntax:
window.frames["FrameName"];
Window.frames.frameName
Window.frames[index]

Where the window typeface can also be replaced or omitted with self, assuming that FrameName is the first frame in the page, the following is equivalent:
self.frames["FrameName"]
Self.frames[0]
Frames[0]
FrameName

Each frame corresponds to an HTML page, so the frame is also a standalone browser window that has all the properties of a window, a reference to a frame that is a reference to a Window object. With this Window object, you can easily manipulate 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 inside the frame, and so on.
The following are references to each other between different levels of frameworks:

1. Reference to the parent frame to the child frame
Knowing the above principle, referencing the child frame from the parent frame becomes very easy, namely:
window.frames["FrameName"];

This refers to a child frame named FrameName within the page. If you want to refer to a child frame within a child frame, you can do so by referring to a frame that is actually the nature of the Window object:
window.frames["FrameName"].frames["frameName2"];

This refers to a two-level child framework, and so on, you can implement a reference to a multi-tier framework.

2. Child frame to Parent frame reference
Each Window object has a parent attribute, which represents its parental frame. If the frame is already a top-level frame, window.parent also represents the framework itself.

3. The reference between the brothers frame
If two frames are a child of a framework, they are called sibling frameworks, and can be referenced through the parent framework, such as a page that includes 2 child frames:
<frameset rows= "50%,50%" >
<frame src= "1.html"/>
<frame src= "2.html"/>
</frameset>

You can use the following statement to refer to frame2 in frame1:
self.parent.frames["Frame2"];

4. Mutual reference between different levels of frames
The hierarchy of the framework is for the top level framework. When levels are different, you can easily access each other by knowing the hierarchy and the hierarchy and name of the other frame, and by using the Window object properties referenced by the framework, for example:
self.parent.frames["ChildName"].frames["Targetframename"];

5. References to top-level frames
Like the Parent property, the Window object also has a top property. It represents a reference to the top-level framework, which can be used to determine whether a frame itself is a top-level frame, for example:
Determine if this frame is a top-level frame
if (self==top) {
DoSomething
}


Current 1/2 page 12 Next read the full text
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.