lqb

我一直在努力!
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

Iframe自动适应宽度和高度(both IE and Firefox are ok)

Posted on 2008-03-28 18:26  BlackPhoenix  阅读(2553)  评论(3编辑  收藏  举报
只需修改框架页
<!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=utf-8" />
<title>iframe</title>
</head>
<body>
<script type="text/javascript">
 
function SetCwinHeight(){
  
var bobo=document.getElementById("bobo"); //iframe id
  if (document.getElementById){
   
if (bobo && !window.opera){
    
if (bobo.contentDocument && bobo.contentDocument.body.offsetHeight){
     bobo.height 
= bobo.contentDocument.body.offsetHeight;
    }
else if(bobo.Document && bobo.Document.body.scrollHeight){
     bobo.height 
= bobo.Document.body.scrollHeight;
    }
   }
  }
 }
</script>
<iframe width="100%" id="bobo" onload="Javascript:SetCwinHeight()" height="1" frameborder="0" src="IFrame_myPage.aspx"></iframe>
这里有什么?
</body>
</html>

如果需要调用其他网站提供的IFrame,把代码写在IFrame_myPage.aspx中,不要直接写src="***"