`
paper
  • 浏览: 74351 次
  • 性别: Icon_minigender_1
  • 来自: 郴州
社区版块
存档分类
最新评论

iframe自动适应高度

 
阅读更多

1、第一个适应高度的方案

<script type="text/javascript" language="javascript"> 

function iFrameHeight() { 

var ifm= document.getElementById("iframepage");

var subWeb = document.frames ? document.frames["iframepage"].document : ifm.contentDocument; 

if(ifm != null && subWeb != null) { 

ifm.height = subWeb.body.scrollHeight; 

</script>



<iframe src="/custom/job/question.do" scrolling="no" style="border: medium none;  width: 710px; overflow: hidden;" id="iframepage" name="iframepage" onLoad="iFrameHeight()"> </iframe>

2、别人自适应的方案
 <!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="textml; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<script language="javascript" type="text/javascript"> 
function dyniframesize(down) { 
var pTar = null; 
if (document.getElementById){ 
pTar = document.getElementById(down); 

else{ 
eval('pTar = ' + down + ';'); 

if (pTar && !window.opera){ 
//begin resizing iframe 
pTar.style.display="block" 
if (pTar.contentDocument && pTar.contentDocument.body.offsetHeight){ 
//ns6 syntax 
pTar.height = pTar.contentDocument.body.offsetHeight +20; 
pTar.width = pTar.contentDocument.body.scrollWidth+20; 

else if (pTar.Document && pTar.Document.body.scrollHeight){ 
//ie5+ syntax 
pTar.height = pTar.Document.body.scrollHeight; 
pTar.width = pTar.Document.body.scrollWidth; 



</script> 
<iframe src ="b.html" frameborder="0" marginheight="0" marginwidth="0" frameborder="0" scrolling="auto" id="ifm" name="ifm" onload="javascript:dyniframesize('ifm');" width="100%"> 
</iframe> 

</body>
</html> 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics