When using an iframe, it may involve passing values and calling methods between parent and child windows. I was a little confused before, and I didn't bother to figure it out. I have to work these two days, and I have no choice but to figure it all out. . It's actually very simple, just a few usages and a few lines of code.
Call the js method of the parent window in the child window:
parent.changeBtnTitle('tzgg');
A parent window may have several child windows with similar functions and behaviors. The components in the child windows need to call the same or similar objects. Or method, then write such a method in the parent window and achieve different effects by passing parameters.
The parent window gets an object in the child window:
First get the iframe object of the child window, for example:
var frameName = window.frames["frameId"]
Then you want to get the document of the sub-window value, and then you can call the object in the child window. In order to avoid repeated writing when using it in the parent window, you might as well write a method:
getSubWindowObj = function(moduleName){
return window.frames["iframe" moduleName].document.getElementById("moreorless" moduleName);
}
Here only I used a parameter just because my iframeId and the object ID of the sub-window were named regularly. I just need to pass in a parameter and splice it together.
Similarly, when a child page calls an element of a parent page, you can use the following code:
parent.window.document.getElementById('parentMenu');
//Abbreviation
parent.document.getElementById('parentMenu');