您的位置:首页 > 编程语言

iframe自适应的代码

2007-12-03 16:26 351 查看
<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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: