iframe自适应高度(简单经典)兼容ie6-ie9 ,firefox,opera,chrome

代码非常简单在需要自适应高度的iframe里面调用iFrameHeight函数即可

经过ie6-ie9 ,firefox,opera,chrome测试完全兼容

你可以自己创建一个iframe页面来测试

ps:记得给iframe加id和name值

<html> <head> <meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″/> <title>iframe自适应高度</title> <script type=”text/javascript” language=”javascript”>    function iFrameHeight(id,name) {    var ifm= document.getElementById(id);      var subWeb = document.frames ? document.frames[name].document : ifm.contentDocument;     if(ifm != null && subWeb != null) {      ifm.height = subWeb.body.scrollHeight;   }     }    </script> </head> <body> <iframe src=”zi.html” id=”iframepage” name=”iframepage” frameBorder=0 scrolling=no width=”100%” onLoad=”iFrameHeight(this.id,this.name)” ></iframe> </body> </html>

转自http://www.cnblogs.com/robinli/archive/2013/05/30/3109444.html

标签:none