Find the following js
Copy codeThe 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 jsCopy codeThe Code is as follows: <Head>
<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>
</Head>
<Body>
<Iframe src = "20103622440.html" onload = "SetCwinHeight (this);" width = "600px">
</Body>
</Html>
In this way, we finally adapted the three browsers.
Be careful as a programmer
Test again
OK... the three browsers are normally displayed, and there is no vertical scroll bar for iframe.