您的位置:首页 > 其它

iframe 子页面自适应高度问题

2017-08-30 17:26 253 查看

1:只需要在父页面添加以下代码即可,目前支持Google和IE,火狐浏览器,其他浏览器没试。效果:可以保证动态地改变iframe的src加载不同页面时,子页面都能自适应高度!

<script type="text/javascript">
//这里代码解决:iframe 被其他页面撑开太高,可以恢复自适应高度
function setIframeHeight(){
if(window.navigator.userAgent.indexOf("Chrome") !== -1){//谷歌浏览器
document.getElementById('iframeReport').height=document.getElementById('iframeReport').contentWindow.document.documentElement.scrollHeight;
}else{//IE或火狐
document.getElementById('iframeReport').height=$("#iframeReport").contents().find("body")[0].scrollHeight;
}
}
</script>


<iframe src="${ctx}/pages/networkquota/areaNetworkReport/netWorkingQuality.jsp" marginheight="0" marginwidth="0" frameborder="0" scrolling="no" width="100%"
height="300px" id="iframeReport" name="iframeReport" onload="setIframeHeight();"></iframe>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息