This article mainly introduces the Case Analysis of FRAME operations in JS, and details various access problems in js frame operations, for more information about FRAME operations in JS, see the examples in this article. 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:
The Code is as follows:
Window. frames ("frameA"). contentWindow. name
Or
The Code is as follows:
Document. getElementById ("frameA"). contentWindow. name
Or
The Code is as follows:
Jquery: window. $ ("# frameA") [0]. contentWindow. name
② Access method func
If you operate in frameABC, you can:
The Code is as follows:
Window. frames ("frameA"). contentWindow. func ();
Or
The Code is as follows:
Document. getElementById ("frameA"). contentWindow. func ();
Or
The Code is as follows:
Jquery: window. $ ("# frameA") [0]. contentWindow. func ();
③ Access sub-page element: username
If you operate in frameABC, you can:
The Code is as follows:
Window. frames ("frameA" 2.16.content20.doc ument. getElementById ("username ");
Or
The Code is as follows:
Document. getElementById ("frameA" ).content#doc ument. getElementById ("username ");
Or
The 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:
The Code is as follows:
Window. parent. name;
② Access the parent PAGE method func. If you operate in frameA (Child page), you can:
The 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:
The Code is as follows:
Window. parent. $ ("# username ")
Or:
The Code is as follows:
Response 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.