经典代码 iFrame 自适应高度,在IE6/IE7/IE8/Firefox/Opera/Chrome/Safari通过测试。

很古老的方法:

<iframe src="../Index.aspx" id="iframe" frameborder="0" scrolling="no" onload="iFrameHeight();" width="100%"></iframe>
function iFrameHeight() {
var ifm = document.getElementById("iframe");
var subWeb = document.frames ? document.frames["iframe"].document : ifm.contentDocument;
if (ifm != null && subWeb != null) {
ifm.height = subWeb.body.scrollHeight;
}
}

下面的两种Jquery方法选择一种即可,很简单,不用判断浏览器高度、宽度等。

jquery代码1:

//注意:下面的代码是放在iframe引用的子页面中调用
$(window.parent.document).find("#iframe").load(function(){
var main = $(window.parent.document).find("#iframe");
var thisheight = $(document).height()+30;
main.height(thisheight);
});

jquery代码2:

//注意:下面的代码是放在和iframe同一个页面调用
$("#iframe").load(function(){
var mainheight = $(this).contents().find("body").height()+30;
$(this).height(mainheight);
});

还有其他的种种...

最新文章

  1. 控制Arduino的利器-Windows Remote Arduino
  2. c++11的初始化
  3. ACM: Gym 100935F A Poet Computer - 字典树
  4. How to create a project with Oracle Policy Modeling
  5. Linux LVS Nginx HAProxy 优缺点
  6. MySql解决插入中文乱码问题
  7. 背包九讲 附:USACO中的背包问题
  8. Qt库的静态编译
  9. Side-by-side assembly
  10. 利用python分析nginx日志
  11. php讲中文json数据编码
  12. js数组元素的添加和删除
  13. 遍历 Map 的四种方法
  14. XML学习总结一
  15. zabbix server is not running,the information dispalyed may not be current
  16. 网络编程 -- RPC实现原理 -- RPC -- 迭代版本V4 -- 远程方法调用 整合 Spring 自动注册
  17. java泛型中&lt;?&gt;和&lt;T&gt;区别
  18. hdu3068 最长回文 manacher
  19. [Windows Azure] Virtual Machine and Cloud Service Sizes for Windows Azure
  20. Pywinauto 基于Win32 程序的自动化功能测试工具

热门文章

  1. iOS开发网络篇—简单介绍ASI框架的使用
  2. html5 canvas围绕中心点旋转
  3. spark的安装
  4. (喷血分享)利用.NET生成数据库表的创建脚本,类似SqlServer编写表的CREATE语句
  5. Python 模块,数据类型,元组
  6. javascript jsscript .js xml html json soap
  7. 0-systemctl开机启动项
  8. poj 1888 Crossword Answers 模拟题
  9. QQ 图片
  10. POJ - 2183 Bovine Math Geniuses