0
点赞
收藏
分享

微信扫一扫

JS 自适应浏览器大小

<script type="text/javascript" language="javascript"> 
    
<!--var iframeids=["把要自适应宽度的ID传进来"]
//如果用户的浏览器不支持iframe是否将iframe隐藏 yes 表示隐藏,no表示不隐藏
var iframehide="yes";
var windowWidth, windowHeight;
function dyniframesize1() 
{
var xScroll, yScroll;     
   if (window.innerHeight && window.scrollMaxY) {     
       xScroll = document.body.scrollWidth; 
       yScroll = window.innerHeight + window.scrollMaxY; 
   } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac 
       xScroll = document.body.scrollWidth; 
       yScroll = document.body.scrollHeight; 
   } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari 
       xScroll = document.body.offsetWidth; 
       yScroll = document.body.offsetHeight; 
   }    
   if (self.innerHeight) {    // all except Explorer 
       windowWidth = self.innerWidth; 
       windowHeight = self.innerHeight; 
   } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode 
       windowWidth = document.documentElement.clientWidth; 
       windowHeight = document.documentElement.clientHeight; 
   } else if (document.body) { // other Explorers 
       windowWidth = document.body.clientWidth; 
       windowHeight = document.body.clientHeight; 
   }               
   if(yScroll < windowHeight){ 
       pageHeight = windowHeight; 
   } else { 
       pageHeight = yScroll; 
   }   if(xScroll < windowWidth){     
       pageWidth = windowWidth; 
   } else { 
       pageWidth = xScroll; 
   } 
   
var dyniframe=new Array()
for (i=0; i<iframeids.length; i++)
{
   if (document.getElementById)
   {
    //自动调整iframe高度
    dyniframe[dyniframe.length] = document.getElementById(iframeids[i]);
    if (dyniframe[i] && !window.opera)
    {
     dyniframe[i].style.display="block"
     if (dyniframe[i].contentDocument && dyniframe[i].contentDocument.body.offsetHeight) //如果用户的浏览器是NetScape
      dyniframe[i].height = dyniframe[i].contentDocument.body.offsetHeight; 
     else if (dyniframe[i].Document && dyniframe[i].Document.body.scrollHeight) //如果用户的浏览器是IE
      dyniframe[i].height = (windowHeight);
      dyniframe[i].width = (windowWidth);
      document.getElementById("ReportViewer1").style.height = windowHeight - 39 - 104 ;
      //document.getElementById("rsvw1").document.all.style.clear;
    // var collAll = document.frames("rsvw1").document.all;
    // collAll.      //alert(document.getElementById("rsvw1").style.height );
    }
   }
   //根据设定的参数来处理不支持iframe的浏览器的显示问题
   if ((document.all || document.getElementById) && iframehide=="no")
   {
    var tempobj=document.all? document.all[iframeids[i]] : document.getElementById(iframeids[i])
    tempobj.style.display="block"
   }
}
}if (window.addEventListener)
window.addEventListener("load", dyniframesize1, false)
else if (window.attachEvent)
window.attachEvent("onload", dyniframesize1)
else
window.onload=dyniframesize1;
window.onresize = dyniframesize1;
-->
    </script>

举报

相关推荐

0 条评论