日期:2014-05-18  浏览次数:20400 次

关于iframe的问题
我在iframe中设置with   ,height为100%   ie   中显示正常可firefox中高度总是不对
在网上查到一些   设置iframe   高度的javascript   可在运行网页的时候总是抛出IE错误信息提示
权限不够

哪位有相同   经历   清帮忙解决多谢

------解决方案--------------------
在你iframe页面中加上下面的JS代码
// 自动调整高度
function iframeAutoFit()
{
if(window!=parent)
{
var a = parent.document.getElementsByTagName( "iframe ");
for(var i=0; i <a.length; i++)
{
if(a[i].contentWindow==window)
{
var h1=0, h2=0;
a[i].parentNode.style.height = a[i].offsetHeight + "px ";
a[i].style.height = "10px ";
if(document.documentElement&&document.documentElement.scrollHeight)
{
h1=document.documentElement.scrollHeight;
}
if(document.body) h2=document.body.scrollHeight;

var h=Math.max(h1, h2);
if(document.all) {h += 4;}
if(window.opera) {h += 1;}
a[i].style.height = a[i].parentNode.style.height = h + "px ";
}
}
}
}
window.onload=iframeAutoFit;