This article discusses the operational problems of FRAME in JS and shares it for your reference. The specific analysis is as follows:
The above figure is an example. Here, the interoperability between frames is simply listed as: 1 variable 2 method 3 mutual acquisition of elements between pages.
1. First, from parent (frameABC)------->child (frameA,frameB,frameC)
① Access variable name name
If you operate in frameABC, you can:
The code copy is as follows: window.frames("frameA").contentWindow.name
Or copy the code as follows: document.getElementById("frameA").contentWindow.name
Or copy the code as follows: jquery: window.$("#frameA")[0].contentWindow.name
② Access method func
If you operate in frameABC, you can:
The code copy is as follows: window.frames("frameA").contentWindow.func();
Or copy the code code as follows: document.getElementById("frameA").contentWindow.func();
Or copy the code as follows: jquery: window.$("#frameA")[0].contentWindow.func();
③ Visit subpage elements: username
If you operate in frameABC, you can:
The code copy is as follows: window.frames("frameA").contentWindow.document.getElementById("username");
Or copy the code code as follows: document.getElementById("frameA").contentWindow.document.getElementById("username");
Or copy the code code as follows: jquery: window.$("#frameA")[0].contentWindow.$("#username");
2. Then from child (frameA,frameB,frameC)------------> to parent (frameABC)
① Visit the parent page variable name. If it is operated in frameA (subpage) then it can:
The code copy is as follows: window.parent.name;
② The method of accessing the parent page func, if it is operated in frameA (subpage) then it can:
The code copy is as follows: window.parent.func();
③ Visit the parent page element username, if it is operated in frameA (subpage) then it can:
Copy the code as follows: window.parent.$("#username")
Or: copy the code code as follows: window.parent.document.getElementById("username");
Summarize:
The frame is just a page frame. If you want to operate elements in a subframe, you need to first enter window or contentWindow. Accessing the parent page from the child page requires calculating the parent-son relationship and dividing it into several layers.
I read other posts online and talked about issues regarding page loading. It probably means that if the subframe page is loaded, it will cause bugs. Interested friends can test it in a targeted manner, and I believe there will be new gains!
I hope this article will be helpful to everyone's JavaScript programming.