完美实现跨域Iframe高度自适应

<html>
<head>
<style>
body {margin-left: 0px;margin-top: 0px;margin-right: 0px;margin-bottom: 0px;overflow: hidden;}
</style>
</head>
 
<body>
<iframe src='http://hi.baidu.com/' width='100%' height='100%' frameborder='0' scrolling="yes" name="_blank" id="_blank" ></iframe>
 
</body>
 
</html>

代码强大之处:

1. 该方法完美兼容IE6,7,8 ,Fire fox,chrome,opera 等主流的浏览器;
2.同域,跨域皆支持;
3.不调用任何JS脚本;
注意三点.
1. 文件开头不能是:

<!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">

必须 是<html>开头

2. body样式中的 overflow: hidden; 绝对不对省略;

3.Iframe 中的 height='100%' 以及 滚动条不能设为no(默认是yes,不用设置即可)



好了,马上试试吧。100%不会让你失望。