javascript應(yīng)用:Iframe自適應(yīng)其加載的內(nèi)容高度
更新時間:2007年04月10日 00:00:00 作者:
main.htm:
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=gb2312'>
<meta name='author' content='F.R.Huang(meizz梅花雪)//www.meizz.com'>
<title>iframe自適應(yīng)加載的頁面高度</title>
</head>
<body>
<iframe src="child.htm"></iframe>
</body>
</html>
child.htm:
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=gb2312'>
<meta name='author' content='F.R.Huang(meizz梅花雪)//www.meizz.com'>
<title>iframe 自適應(yīng)其加載的網(wǎng)頁(多瀏覽器兼容)</title>
<script language=javascript>
function iframeAutoFit()
{
try
{
if(window!=parent)
{
var a = parent.document.getElementsByTagName("IFRAME");
for(var i=0; i<a.length; i++) //author:meizz
{
if(a[i].contentWindow==window)
{
var h = document.body.scrollHeight;
if(document.all) {h += 4;}
if(window.opera) {h += 1;}
a[i].style.height = h;
}
}
}
}
catch (ex)
{
alert("腳本無法跨域操作!");
}
}
if(document.attachEvent) window.attachEvent("onload", iframeAutoFit);
else window.addEventListener('load', iframeAutoFit, false);
</script>
</head>
<body>
<div style="width: 200; height: 400; background-color: yellow">
iframe 自適應(yīng)其加載的網(wǎng)頁(多瀏覽器兼容)
</div>
</body>
</html>
復(fù)制代碼 代碼如下:
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=gb2312'>
<meta name='author' content='F.R.Huang(meizz梅花雪)//www.meizz.com'>
<title>iframe自適應(yīng)加載的頁面高度</title>
</head>
<body>
<iframe src="child.htm"></iframe>
</body>
</html>
child.htm:
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=gb2312'>
<meta name='author' content='F.R.Huang(meizz梅花雪)//www.meizz.com'>
<title>iframe 自適應(yīng)其加載的網(wǎng)頁(多瀏覽器兼容)</title>
<script language=javascript>
function iframeAutoFit()
{
try
{
if(window!=parent)
{
var a = parent.document.getElementsByTagName("IFRAME");
for(var i=0; i<a.length; i++) //author:meizz
{
if(a[i].contentWindow==window)
{
var h = document.body.scrollHeight;
if(document.all) {h += 4;}
if(window.opera) {h += 1;}
a[i].style.height = h;
}
}
}
}
catch (ex)
{
alert("腳本無法跨域操作!");
}
}
if(document.attachEvent) window.attachEvent("onload", iframeAutoFit);
else window.addEventListener('load', iframeAutoFit, false);
</script>
</head>
<body>
<div style="width: 200; height: 400; background-color: yellow">
iframe 自適應(yīng)其加載的網(wǎng)頁(多瀏覽器兼容)
</div>
</body>
</html>
您可能感興趣的文章:
- js檢測iframe是否加載完成的方法
- js下判斷 iframe 是否加載完成的完美方法
- JS加載iFrame出現(xiàn)空白問題的解決辦法
- 基于JS判斷iframe是否加載成功的方法(多種瀏覽器)
- JS iFrame加載慢怎么解決
- js通過iframe加載外部網(wǎng)頁的實現(xiàn)代碼
- javascript實現(xiàn)iframe框架延時加載的方法
- 動態(tài)加載js、css等文件跨iframe實現(xiàn)
- javascript firefox 自動加載iframe 自動調(diào)整高寬示例
- js中頁面的重新加載(當(dāng)前頁面/上級頁面)及frame或iframe元素引用介紹
- JS判斷iframe是否加載完成的方法
相關(guān)文章
關(guān)于javascript document.createDocumentFragment()
documentFragment 是一個無父對象的document對象.2009-04-04