Analysis of FRAME Operation Problems in JS, and Analysis of frame instances

Source: Internet
Author: User

Analysis of FRAME Operation Problems in JS, and Analysis of frame instances

This article discusses FRAME operations in JS and shares it with you for your reference. The specific analysis is as follows:

For example, here, the mutual operations between frames are simply listed as: 1 variable 2 method 3 mutual acquisition of elements between pages.

1. First, from the parent (frameABC) -------> child (frameA, frameB, frameC)

① Access variable name

If you operate in frameABC, you can:
Copy codeThe Code is as follows: window. frames ("frameA"). contentWindow. name

OrCopy codeThe Code is as follows: document. getElementById ("frameA"). contentWindow. name

OrCopy codeThe Code is as follows: jquery: window. $ ("# frameA") [0]. contentWindow. name

② Access method func

If you operate in frameABC, you can:
Copy codeThe Code is as follows: window. frames ("frameA"). contentWindow. func ();

OrCopy codeThe Code is as follows: document. getElementById ("frameA"). contentWindow. func ();

OrCopy codeThe Code is as follows: jquery: window. $ ("# frameA") [0]. contentWindow. func ();

③ Access sub-page element: username

If you operate in frameABC, you can:
Copy codeThe Code is as follows: window. frames ("frameA" mirror.contentdomaindoc ument. getElementById ("username ");

OrCopy codeThe Code is as follows: document. getElementById ("frameA" pai.content?#doc ument. getElementById ("username ");

OrCopy codeThe Code is as follows: jquery: window. $ ("# frameA") [0]. contentWindow. $ ("# username ");

2. Then, from child (frameA, frameB, frameC) ------------> to parent (frameABC)

① Access the parent page variable name. If you perform the following operations in frameA (Child page:
Copy codeThe Code is as follows: window. parent. name;

② Access the parent PAGE method func. If you operate in frameA (Child page), you can:
Copy codeThe Code is as follows: window. parent. func ();

③ Access the username element of the parent page. If the username is used in frameA (sub-page), you can:
Copy codeThe Code is as follows: window. parent. $ ("# username ")

Or:Copy codeThe Code is as follows: Upload response parent.doc ument. getElementById ("username ");

Summary:

Frame is only a page frame. To operate the elements in the sub-frame, you must first enter the window or contentWindow. When accessing the parent page from a child page, you need to calculate the parent-child relationship, which is divided into several layers.

I read other posts online and talked about page loading issues. It probably means that element operations are performed before the sub-frame page is loaded, which may cause bugs. Interested friends can perform targeted tests and I believe there will be new gains!

I hope this article will help you design javascript programs.


Operate frame with js

Window. frames. frmRightName or window. frames ["frmRightName"] can locate the right frame. Next, add the div directly to frmRightName.
 
Question about js iframe operations

<Script type = "text/javascript">
Window. onload = function (){
Var ads = document. getElementsByName ('ys _ ad ');
Var ads_len = ads. length;
Var webs = ['a.com', 'B .com'];
For (I = 0; I <ads_len; I ++ ){
Ads [I]. src = webs [I];
}
}
</Script>

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.