在开发html5的时候,iframe的高度适应是让人头疼的问题,收集到的精品代码
实现代码:iframe跨域html5高度自适应代码(适合大部分浏览器和系统)
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 + 20; //FF NS
else if(cwin.Document && cwin.Document.body.scrollHeight)
cwin.height = cwin.Document.body.scrollHeight + 10;//IE
}
else
{
if(cwin.contentWindow.document && cwin.contentWindow.document.body.scrollHeight)
cwin.height = cwin.contentWindow.document.body.scrollHeight;//Opera
}
}
}
iframe引用
<iframe src=” ” quality=”high” width=”100%” height=”auto” onload=”SetCwinHeight(this);”>