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:
② access to the parent page method Func, if the operation in Framea (subpages) can:
Copy Code code as follows:
③ 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.