Page 1/2 of JavaScript framework programming

Source: Internet
Author: User

Use JavaScript frameworks
When talking about the window object, we mentioned that a webpage in the framework is also a window object, that is, the Frame object is also a window object. In the simplest case, each HTML file occupies a window object, including a webpage defining a framework ("framework webpage "). In IE, "<iframe>" is used to mark the framework inserted in the document as a window object, but "include webpage" is used (displayed as "<! -- Webbot bot = "include"... --> ") the HTML read does not occupy the window object alone. Every frame is a child object of the window object that contains its page (I do not know whether it should be called "attribute" or not). To reference it, you can use one of the following methods:
Window. frames [x]
Window. frames ['framename']
Window. frameName

X indicates the framework specified in the window object. Like other arrays, x starts from scratch. FrameName refers to the Framework name, which is the same as the "name" attribute in <frame>.

If the window object specified by window. frameName is a framework webpage, the method for referencing the framework is window. frameName. subFrameName. And so on.

Note that, no matter where the object is, all objects returned by referencing the "window" object are "current" window objects. If you want to access other window objects, you need to use the parent and top attributes. Parent refers to the "parent" window object, that is, the frame webpage that contains the current window object; top refers to the window object at the top of the window.

You should also pay close attention to the global variables and user-defined functions defined in your JavaScript. They all have their own -- the window object. To reference global variables or udfs in other frameworks, you must use "window objects. Framework objects [. Framework objects…]. Global variables or user-defined functions.

The above problem is often ignored when establishing a connection: if a default target window (<base target = "... ">) in <a href =" javascript :... ">, you must know that the entered JavaScript statement is run in the default target window. If necessary, add the" parent "and" top "attributes.

Framework programming Overview
An HTML page can have one or more child frameworks marked with <iframe> to display an independent HTML page. The framework programming mentioned here includes framework self-control and mutual access between frameworks, for example, you can reference JavaScript variables in another framework from one framework, call functions in another framework, and control the form behavior in another framework.
Mutual reference between frameworks
All frames on a page are provided as properties of the window object in the form of a set, for example, window. frames indicates the set of all frames on the page. This is similar to form objects, link objects, and image objects. The difference is that these sets are the attributes of document. Therefore, to reference a sub-framework, you can use the following syntax:
Window. frames ["frameName"];
Window. frames. frameName
Window. frames [index]

The window can also be replaced or omitted by self. If frameName is the first frame on the page, the following statements are equivalent:
Self. frames ["frameName"]
Self. frames [0]
Frames [0]
FrameName

Each framework corresponds to an HTML page, so this framework is also an independent browser window, which has all the properties of the window. The so-called reference to the framework is also a reference to the window object. With this windowless object, you can easily perform operations on the page. For example, you can use the volume upload Doc ument object to write data to the page, and use the window. location attribute to change pages in the framework.
The following describes the mutual references between frameworks of different levels:

1. Reference from parent framework to Child Framework
With the above principles, it is very easy to reference the sub-framework from the parent framework, that is:
Window. frames ["frameName"];

In this way, the sub-framework named frameName in the page is referenced. If you want to reference the sub-framework in the sub-framework, the referenced framework is actually the nature of the window object, which can be implemented as follows:
Window. frames ["frameName"]. frames ["frameName2"];

In this way, the second-level sub-framework can be referenced, and so on.

2. references from the Child Framework to the parent framework
Each window object has a parent attribute, indicating its parent framework. If the framework is already a top-level framework, window. parent also indicates the framework itself.

3. Reference between sibling frameworks
If the two frameworks are the same as the Child frameworks of the same framework, they are called the sibling frameworks, you can use the parent framework to reference each other. For example, a page contains two child frameworks:
<Frameset rows = "50%, 50%">
<Frame src = "1.html"/>
<Frame src = "2.html"/>
</Frameset>

In frame1, you can use the following statement to reference frame2:
Self. parent. frames ["frame2"];

4. Mutual reference between frameworks of different levels
The framework layer is for the top-level framework. When the layers are different, you only need to know your own layers and the layers and names of another framework, and use the window object properties referenced by the Framework to easily implement mutual access. For example:
Self. parent. frames ["childName"]. frames ["targetFrameName"];

5. Reference to the top-level framework
Similar to the parent attribute, the window object also has a top attribute. It indicates a reference to the top-level framework, which can be used to determine whether a framework itself is a top-level framework. For example:
// Determine whether the framework is a top-level framework
If (self = top ){
// Dosomething
}


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.