Iframe高度自适应IE与FF环境下均可用
看下面的代码:
scripttype="text/javascript"
functionSetCwinHeight(){
varbobo=document.getElementById("bobo");//iframeid
if(document.getElementById){
if(bobo!window.opera){
if(bobo.contentDocumentbobo.contentDocument.body.offsetHeight){
bobo.height=bobo.contentDocument.body.offsetHeight;
}elseif(bobo.Documentbobo.Document.body.scrollHeight){
bobo.height=bobo.Document.body.scrollHeight;
}
}
}
}
/scriptiframewidth="100%"id="bobo"onload="Javascript:SetCwinHeight()"height="1"frameborder="0"src="/"/iframe
查看运行效果:
!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "/TR/xhtml1/DTD/xhtml1-transitional.dtd"html xmlns="/1999/xhtml"headmeta http-equiv="Content-Type" content="text/html; charset=utf-8" /titleIframe高度自适应 IE与FF环境下均可用/title/headbodyscript type="text/javascript"function SetCwinHeight(){var bobo=document.getElementById("bobo"); //iframe idif (document.getElementById){if (bobo !window.opera){if (bobo.contentDocument bobo.contentDocument.body.offsetHeight){bobo.height = bobo.contentDocument.body.offsetHeight;}else if(bobo.Document bobo.Document.body.scrollHeight){bobo.height = bobo.Document.body.scrollHeight;}}}}/scriptiframe width="100%" onload="Javascript:SetCwinHeight()" height="1" frameborder="0" src="/"/iframe/body/html
[ 可先修改部分代码 再运行查看效果 ]