一行代码解决各种IE兼容问题,IE6,IE7,IE8,IE9,IE10 解决了以前头痛的浏览器兼容性问题,最近客户发现项目在谷歌浏览器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" ></iframe> </body> </html>

 

相关文章:

  • 2021-10-15
  • 2021-12-30
  • 2021-05-18
猜你喜欢
  • 2021-12-12
  • 2021-07-07
  • 2022-12-23
  • 2022-12-23
  • 2021-06-07
  • 2021-08-11
  • 2021-09-14
相关资源
相似解决方案