iframe高度自适应的IE解决方案主页面main.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>New Document </title> </head> <body> <style type="text/css"> .iframestyle { height: expression(1); aho: expression(autoResize()); } </style> <script type="text/javascript"> function autoResize() { try { document.getElementById("frm1").style.height = window.frames["frm1"].document.body.scrollHeight; } catch (e) { } } </script> iframe之前的文字<hr/> <iframe name="frm1" src='frm.html' marginwidth="0" marginheight="0" frameborder="0" scrolling="no" width="100%" class="iframestyle" id="frm1" ></iframe> <hr/>iframe之后的文字 </body> </html>
框架子页frm.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>New Document </title> </head> <body> <script language="JavaScript" type="text/javascript"> function fnShort() { document.getElementById("diva").innerHTML = '<br />iframe变短<br />'; } function fnLong() { document.getElementById("diva").innerHTML = '<br />iframe变长<br />iframe变长<br />iframe变长<br />iframe变长<br />iframe变长<br />iframe变长<br />iframe变长<br />iframe变长<br />iframe变长<br />'; } </script> <a href="#" onclick="fnShort();">iframe变短</a> <a href="#" onclick="fnLong();">iframe变长</a> <div id="diva"> <br /> iframe变长<br /> iframe变长<br /> iframe变长<br /> iframe变长<br /> iframe变长<br /> iframe变长<br /> iframe变长<br /> iframe变长<br /> iframe变长<br /> </div> <a href="frm2.html">转到一个新的页面</a> </body> </html>
子页面2: frm2.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>New Document </title> </head> <body> <a href="frm.html">返回frm.html</a> </body> </html>
在IE8上失效(不过IE8上可以通过设置源代码的Meta,让IE8以兼容性视图浏览,也算是一种IE8下的解决办法)。