首页 > 技术文章 > js获取页面高度赋值给div

jinzhiming 2016-01-15 09:43 原文

<script type="text/javascript">
window.onload=function(){
    map_width=document.body.clientWidth;//获取body宽度
    map_height=document.documentElement.clientHeight;//获取页面可见高度
    //alert(map_width);
    //alert(map_height);
    //下面两行最后的"px"必须加上,折腾了半天老是不显示添加的style,最后就是错在这了
    document.getElementByIdx_x_x("maps").style.width=map_width+"px";
    document.getElementByIdx_x_x("maps").style.height=map_height+"px";
    
}
</script> 
function iframeHeight(iframeId,change) { 
    
      var ifm= document.getElementById(iframeId);  

      ifm.name=iframeId;
      
      var clientHeight=document.documentElement.clientHeight;
      
      clientHeight=clientHeight-change;
      
      var subWeb = document.frames ? document.frames[iframeId].document : ifm.contentDocument;   

      if(ifm != null && subWeb != null) {
        
          var scrollHeight=subWeb.body.scrollHeight;

          if(scrollHeight>clientHeight){
              
              ifm.height = clientHeight;
          }else{
            
              ifm.height = scrollHeight;
          }
         
      }   
      
} 

 

推荐阅读