iframe 自动适应页面大小

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script type="text/javascript">
// function SetWinHeight(obj){

//var win=obj;
//if (document.getElementById){
//if (win && !window.opera){
//        alert(win.document.body.scrollHeight);
//    if (win.contentDocument&&win.contentDocument.body.offsetHeight)        
//     win.height = win.contentDocument.body.offsetHeight;        
//  else if(win.Document && win.Document.body.scrollHeight)       
//   win.height = win.document.body.scrollHeight;
//   
//       }
//    }
//
//}
//iframe高度自适应
 //  function reinitIframe(obj){
//    var iframe = obj;
 //   try{
 //   var bHeight = iframe.document.body.scrollHeight+200;
 //   var height = Math.max(bHeight, dHeight);
 //   iframe.height =  height;
// alert(iframe.height);
 //   }catch (ex){
// 
// }
// if(iframe.height<2000)
// window.setTime("reinitIframe()", 200);
//    }
 //var iframe=document.getElementById("win");;
    function reinitIframe(){
 var iframe = document.getElementById("win");
 try{
 var bHeight = iframe.document.body.scrollHeight;
 var client=iframe.document.body.clientHeight;
 var dHeight = iframe.document.documentElement.scrollHeight;
 var height = Math.max(bHeight, dHeight);
 var btitle = iframe.document.title;
 
 iframe.height = document.body.scrollHeight;
 document.title=btitle;
 
 }catch (ex){}
 alert(bHeight);
 alert(client);
 }
 //window.setInterval("reinitIframe()", 2);


 </script>
 </head>
<body onload="parent.document.all.win.style.height=document.body.scrollHeight">


<iframe  align="center" height="600" id="win" width="100%" name="win" src="盾诚科技/dagl.html" onload="javascript:reinitIframe(this)" frameborder="0" scrolling="no">
</iframe>

</body>
</html>

 


 

相关技术帖子:http://blog.sina.com.cn/gzwncb

 

 


 



你可能感兴趣的:(JavaScript,html,function,iframe,XHTML,文档)