`

iframe自适应高度

阅读更多
<html>
<head>
<title></title>
<script>
//iframe自动适应高度
function SetWinHeight(obj)
{   alert(obj);
	var win=obj;
	if (document.getElementById)
	{
	    if (win && !window.opera)
	    {  
	       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;
	       }
	         
	     }
	}
}
   
 </script>
</head>
<body>
  <iframe src="test.html"  name="myframe" id="myframe" width="100%" frameborder="0" onload="SetWinHeight(this)"></iframe>
</body>
</html>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics