iframe嵌套在div内 ,iframe的宽高都设置了100% ,可是还是无法自适应,解决方法如下:
代码:通过红色位置可以解决
function setIframeHeight(iframeId){
var cwin = document.getElementById(iframeId);
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
}
}
};
window.οnlοad=function(){
var a=document.body.clientHeight-182; //取得iframe框架的实际宽度
document.getElementById(“right”).style.height=a+”px”;
}
<div id="right" class="col-sm-10 animated fadeInRight">
<iframe id="cmsArticleContent" name="cmsArticleContent"
src="${ctx}/cms/cmsArticle/list?did=&parentIds=&websiteID=&websiteName=&websiteType=&websiteUnitID="
οnlοad="setIframeHeight(cmsArticleContent);" width="100%" height="100%" frameborder="0" scrolling="no"></iframe>
</div>
版权声明:本文为moxiaoya1314原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。