您的位置:首页 > 其它

iframe自适应高度问题

2015-05-18 22:25 225 查看
正在踌躇的时候发现下面的这段代码,终于得意解决。苦于对js没有足够的熟悉,代码中的具体方法参数还得继续学习,感谢提供代码的朋友。

function SetCwinHeight()

{

var cwin=document.getElementById("cwin");

if (document.getElementById)

{

if (cwin && !window.opera)

{

if (cwin.contentDocument && cwin.contentDocument.body.offsetHeight)

cwin.height = cwin.contentDocument.body.offsetHeight;

else if(cwin.Document && cwin.Document.body.scrollHeight)

cwin.height = cwin.Document.body.scrollHeight;

}

}

}

<iframe width="778" align="center" height="200" id="cwin" name="cwin" onload="Javascript:SetCwinHeight(this)" frameborder="0" scrolling="no"></iframe>

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;

else if(cwin.Document && cwin.Document.body.scrollHeight)

cwin.height = cwin.Document.body.scrollHeight;

}

}

}

引用时

onload="javascript:SetCwinHeight(this)"
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: