Home  >  Article  >  Web Front-end  >  Usage and precautions of iframe_Experience exchange

Usage and precautions of iframe_Experience exchange

WBOY
WBOYOriginal
2016-05-16 12:06:041717browse

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


[Ctrl A Select all Note:If you need to introduce external Js, you need to refresh it to execute]


bb.htm

[Ctrl A 全选 注:如需引入外部Js需刷新才能执行]

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn