Practical Framework (iframe) operation code _ javascript tips-js tutorial

Source: Internet
Author: User
This article mainly introduces the operation code of the practical framework (iframe). If you need it, refer to the common code below:

 

Javascript accesses frame, iframe framework, and href targeting

I. frame

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:

    

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:

The Code is as follows:


// Determine whether the framework is a top-level framework
If (self = top ){
// Dosomething
}

That is

The Code is as follows:


If (window. top! = Window. self ){
// Dosomething
}

Change the loading page of the framework

The reference to the framework refers to the reference to the window object. The location attribute of the window object can be used to change the navigation of the Framework. For example:

Window. frames [0]. location = "1.html ";

Reference JavaScript variables and functions in other frameworks

Before introducing the techniques for referencing JavaScript variables and functions in other frameworks, let's look at the following code:

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.