找到了下面這個js
複製代碼 代碼如下:
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;
}
}
}
然後……
進入了測試過程(調用很簡單,先略過)
1.IE ---通過 但是高度還是有稍微的差距,很小,捲軸還在
2.FF --- 通過 與IE一樣,有小差距
3.Opera --- 看那個JS的條件就知道,通不過的
但主流瀏覽器至少要通過這三項撒!!!
於是,還是Google
搜尋 各瀏覽器在處理 document.scrollHeight 或者 offsetHeigth時的特殊現象
發現,Opera瀏覽器在處理iframe內容的時候,用的是contentWindow
而處理內容高度的時候,卻與IE一致
從而,有了下面這段js
複製代碼 代碼如下:
<html>
<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.contentWindow.document && cwin.contentWindow.document.body.scrollHeight)
cwin.height = cwin.contentWindow.document.body.scrollHeight;//Opera
}
}
}
</script>
</head>
<body>
<iframe src="20103622440.html" onload="SetCwinHeight(this);" width="600px">
</body>
</html>
這樣一來,總算把這三個瀏覽器給適應了
做為程式員,還是要細心點
再測試一下
OK...3個瀏覽器均正常顯示,也無iframe的縱向捲軸了