Objects between the parent and child windows of an IFrame invoke basic usage _javascript tips

Source: Internet
Author: User
The use of IFRAME, may involve the parent-child window between the values and methods of mutual invocation, has been a bit confused, and did not deliberately to find out, these two days to work, can not have to put this all figured out. Actually very simple, just a few uses, a few lines of code just.

The JS method of calling the parent window in a child window:
Copy Code code as follows:

Parent.changebtntitle (' Tzgg ');

A parent window may have several child windows with similar function behavior, and the component in the child window will invoke the same or similar object or method, then write the method in the parent window and pass the parameters to achieve different effects.

The parent window obtains an object from the child window:

First you get the IFrame object for the child window, such as:
Copy Code code as follows:

var framename = window.frames["Frameid"]

Then you get the document value for the child window, and then you can call the object in the child window. To avoid repeated writing when used in a parent window, you might write a method:
Copy Code code as follows:

Getsubwindowobj = function (modulename) {
return window.frames["iframe" +modulename].document.getelementbyid ("moreorless" +modulename);
}

Here only a parameter, because my Iframeid and child window of the object ID name of the law, just pass in a parameter splicing can be hungry.

Similarly, the child page calls the element of the parent page, and you can use the following code:
Copy Code code as follows:

Parent.window.document.getElementById (' Parentmenu ');
Shorthand
Parent.document.getElementById (' Parentmenu ');

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.