Iframe自適應(yīng)其加載的內(nèi)容高度
更新時間:2007年01月23日 00:00:00 作者:
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=gb2312'>
<meta name='author' content='站長中國 http://www.zzcn.net/'>
<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='站長中國 http://www.zzcn.net/'>
<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>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=gb2312'>
<meta name='author' content='站長中國 http://www.zzcn.net/'>
<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='站長中國 http://www.zzcn.net/'>
<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>
相關(guān)文章
css下margin、padding、border、background和font縮寫示例
CSS代碼簡化在工作中是非常有益的,也是必要的。在編寫CSS代碼時,經(jīng)常會出現(xiàn)冗余的代碼,為了提高代碼的質(zhì)量及文件壓縮到最小,使代碼具有可讀性,不得不把CSS代碼簡化。2008-06-06XHTML下css+div布局總結(jié) 超強(qiáng)推薦
XHTML下css+div布局總結(jié) 超強(qiáng)推薦...2006-12-12《CSS3實戰(zhàn)》筆記--漸變設(shè)計(一)
這篇文章主要介紹了《CSS3實戰(zhàn)》筆記--漸變設(shè)計(一,需要的朋友可以參考下2016-05-05