Frame operations in js and jsframe operations

Source: Internet
Author: User

Frame operations in js and jsframe operations

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

A first starts from the parent (frameABC) -------> child (frameA, frameB, frameC)

A1: Access variable name

If you operate in frameABC, you can:

Window. frames ("frameA"). contentWindow. name

Or document. getElementById ("frameA"). contentWindow. name

Or jquery: window. $ ("# frameA") [0]. contentWindow. name

A2: Access Method func

If you operate in frameABC, you can:

Window. frames ("frameA"). contentWindow. func ();

Or document. getElementById ("frameA"). contentWindow. func ();

Or jquery: window. $ ("# frameA") [0]. contentWindow. func ();

A3: Access sub-page element: username

If you operate in frameABC, you can:

Window. frames ("frameA" 2.16.content20.doc ument. getElementById ("username ");

Alternatively, document. getElementById ("frameA" ).content#doc ument. getElementById ("username ");

Or jquery: window. $ ("# frameA") [0]. contentWindow. $ ("# username ");

B then from child (frameA, frameB, frameC) ------------> to parent (frameABC)

B1: access the parent page variable name. If you want to perform the following operations in frameA:

Window. parent. name;

B2: the func Method for accessing the parent page. If you want to perform the following operations in frameA:

Window. parent. func ();

B3: access the username element of the parent page. You can perform the following operations in frameA:
Window. parent. $ ("# username ")

Alternatively, upload your parent.doc ument. getElementById ("username ");

------------------------------------------------------------------------------

Summary: frame is only a page frame. To operate the elements in a 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. If you are interested, you can write your own opinions below.


Operate frame with js

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

You can use parent. xx to access the parent page in iframe, for example:
Parent.doc ument. getElementById ("abc"). value = "";
The premise is that the two pages must be under the same domain name, that is, cross-origin access is not allowed.

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.