Example analysis of operation problem of frame in JS _javascript skill

Source: Internet
Author: User

In this paper, we discuss the operation of the frame in JS and share it for everyone's reference. The specific analysis is as follows:

The above diagram, for example, is a simple list of the interaction between the frame: 1 Variable 2 Method 3 page elements of the mutual gain.

First, from the Father (FRAMEABC)-------> (FRAMEA,FRAMEB,FRAMEC)

① Access Variable name name

If you operate in Frameabc, you can:

Copy Code code as follows:
Window.frames ("Framea"). Contentwindow.name

Or

Copy Code code as follows:
document.getElementById ("Framea"). Contentwindow.name

Or

Copy Code code as follows:
jquery:window.$ ("#frameA") [0].contentwindow.name

② Access Method func

If you operate in Frameabc, you can:

Copy Code code as follows:
Window.frames ("Framea"). Contentwindow.func ();

Or

Copy Code code as follows:
document.getElementById ("Framea"). Contentwindow.func ();

Or

Copy Code code as follows:
jquery:window.$ ("#frameA") [0].contentwindow.func ();

③ access to Child page elements: username

If you operate in Frameabc, you can:

Copy Code code as follows:
Window.frames ("Framea"). ContentWindow.document.getElementById ("username");

Or

Copy Code code as follows:
document.getElementById ("Framea"). ContentWindow.document.getElementById ("username");

Or

Copy Code code as follows:
jquery:window.$ ("#frameA") [0].contentwindow.$ ("#username");

Second, then from the Child (Framea,frameb,framec)------------> to the Father (FRAMEABC)

① access to the parent page variable name, in the case of a framea (subpage) operation:

Copy Code code as follows:
Window.parent.name;

② access to the parent page method Func, if the operation in Framea (subpages) can:

Copy Code code as follows:
Window.parent.func ();

③ access to the parent page element username, if the Framea (subpage) operation is possible:

Copy Code code as follows:
window.parent.$ ("#username")

Or:

Copy Code code as follows:
Window.parent.document.getElementById ("username");

Summarize:

Frame is just a page frame and you need to first enter the window or Contentwindow to manipulate the elements in the child frame. From the child page to access the parent page, you need to calculate a good parent-child relationship, divided into several layers of structure.

Read other posts on the web and talk about page loading issues. Probably means that the child frame page has not been loaded out of the element operation, will cause bugs, interested friends can be targeted testing, I believe there will be new harvest!

I hope this article will help you with your JavaScript programming.

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.