To meet project requirements, I used an iframe highly adaptive function. I searched google for a long time and found some modifications. You can test it. Find the following js
The Code is as follows:
Function SetCwinHeight (obj)
{
Var cwin = obj;
If (document. getElementById)
{
If (cwin &&! Window. opera)
{
If (cwin. contentDocument & cwin. contentDocument. body. offsetHeight)
Cwin. height = cwin. contentDocument. body. offsetHeight + 20;
Else if (cwin. Document & cwin. Document. body. scrollHeight)
Cwin. height = cwin. Document. body. scrollHeight + 10;
}
}
}
Then ......
The test process is started (the call is simple and skipped first)
1. IE --- there is a slight gap between the height and the size of the scroll bar.
2. FF --- similar to IE, there is a small gap
3. Opera --- you can see the JS conditions.
However, mainstream browsers must use at least these three items !!!
So Google
Search for special phenomena that browsers encounter when processing document. scrollHeight or offsetHeigth
It is found that when Opera Browser processes iframe content, it uses contentWindow
However, when the processing content is high, it is consistent with IE.
Thus, with the following section of js
The Code is as follows:
Script
Function SetCwinHeight (obj)
{
Var cwin = obj;
If (document. getElementById)
{
If (cwin &&! Window. opera)
{
If (cwin. contentDocument & cwin. contentDocument. body. offsetHeight)
Cwin. height = cwin. contentDocument. body. offsetHeight + 20; // FF NS
Else if (cwin. Document & cwin. Document. body. scrollHeight)
Cwin. height = cwin. Document. body. scrollHeight + 10; // IE
}
Else
{
If(cwin.content+doc ument & cwin.content+doc ument. body. scrollHeight)
Cwin. height = cwin.content20.doc ument. body. scrollHeight; // Opera
}
}
}
Script
<BR> </body> <BR> </ptml> <BR> </p> <BR>, finally, we adapted these three browsers. <BR> as a programmer, we still need to be careful. <BR> try again. <BR> OK... the three browsers are normally displayed, and there is no vertical scroll bar for iframe.