`
ry.china
  • 浏览: 137399 次
  • 性别: Icon_minigender_1
  • 来自: 重庆
社区版块
存档分类
最新评论

Iframe自适应高度_ie_firefox下都可用

阅读更多

<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="/default.asp?cateID=1"></iframe>

 

HTML代码:

 

<!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="/default.asp?cateID=1"></iframe>
这里写几个字试试!子鼠!
</body>
</html>

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics