This article mainly talks about the usage and precautions of iframe:
Many comrades do not know very much about how iframe is controlled, and they are basically still in a vague state of understanding.
Pay attention to two things, ifr is the ID and NAME value of an existing iframe:
document.getElementById(“ifr”);
window.frames[“ifr”];
To use iframe function, the variables must go through the second method. Because it takes a complete DOM model (I don’t know if this is correct). The first method just takes out an OBJECT.
If only If you want to change the iframe's src or border, scrolling and other attributes (which are not the same concept as property, property cannot be written in tags, such as: scrollHeight, innerHTML, etc.), you need to use the first method.
If you want to get the iframe page (not the iframe itself), you need to use the second method, because it gets a complete DOM model. For example, if you want to get the content of the iframe's document.body, you can only use the second method.
Also note that if you call the iframe's DOM model when the iframe page is not fully loaded, a serious error will occur, so you need to prepare a fault-tolerant mode.
The following are examples, one is aa.htm and the other is bb.htm. Please check that it is running locally first. I don’t need to explain the reasons!
aa.htm