首页 > 其他 > 详细

让iframe高度自适应

时间:2015-03-20 11:01:43      阅读:302      评论:0      收藏:0      [点我收藏+]

总结两种方法,第一种是在网上查资料然后总结出来的,兼容性比较好,支持IE8,以及其他的标准浏览器,IE8以下版本没有测试,IE8以上版本基本都支持,这种方法是通过js来调整iframe的宽高的,第二种方法很简单,是我看朋友是这样的写的,具体兼容性没有测试,应该不会差。不多少了,直接贴代码:

第一种:

  <script type="text/javascript"> 
  function findDimensions(){  //函数:获取尺寸
  var winWidth = 0; 
var winHeight = 0; 
//获取窗口宽度 
if (window.innerWidth){ 
winWidth = window.innerWidth; 
}else if ((document.body) && (document.body.clientWidth)){ 
winWidth = document.body.clientWidth;
}
//获取窗口高度 
if (window.innerHeight){  
winHeight = window.innerHeight; 
}else if ((document.body) && (document.body.clientHeight)){ 
winHeight = document.body.clientHeight;
}
//通过深入Document内部对body进行检测,获取窗口大小 
if (document.documentElement && document.documentElement.clientHeight && document.documentElement.clientWidth){ 
winHeight = document.documentElement.clientHeight; 
winWidth = document.documentElement.clientWidth; 

//调整div的高度以及iframe的宽高 
var iframehei = winHeight - 180;
var iframeWid = winWidth - 310;
document.getElementById("Conframe").style.height=iframehei+"px";
document.getElementById("Conframe").style.width=iframeWid+"px";

  
  $(document).ready(function(){
findDimensions();
menuOnClick("homePage/homePage.do"); 
});
//调用函数,获取数值 
$(window).resize(function(){
findDimensions();
});
  </script>


第二种:

 <iframe name="main" src="home.jsp" width=100% onload="this.height=this.contentWindow.document.body.scrollHeight" frameborder=No border=0 marginwidth=0 marginheight=0 scrolling=no></iframe>(第二种是不是很简单?直接这样就行了
onload="this.height=this.contentWindow.document.body.scrollHeight"


让iframe高度自适应

原文:http://blog.csdn.net/s592652578/article/details/44487107

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!