jquery iframe自适应高度[转]
2024-09-26 02:42:38
经典代码 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);
});
还有其他的种种...
最新文章
- 控制Arduino的利器-Windows Remote Arduino
- c++11的初始化
- ACM: Gym 100935F A Poet Computer - 字典树
- How to create a project with Oracle Policy Modeling
- Linux LVS Nginx HAProxy 优缺点
- MySql解决插入中文乱码问题
- 背包九讲 附:USACO中的背包问题
- Qt库的静态编译
- Side-by-side assembly
- 利用python分析nginx日志
- php讲中文json数据编码
- js数组元素的添加和删除
- 遍历 Map 的四种方法
- XML学习总结一
- zabbix server is not running,the information dispalyed may not be current
- 网络编程 -- RPC实现原理 -- RPC -- 迭代版本V4 -- 远程方法调用 整合 Spring 自动注册
- java泛型中<;?>;和<;T>;区别
- hdu3068 最长回文 manacher
- [Windows Azure] Virtual Machine and Cloud Service Sizes for Windows Azure
- Pywinauto 基于Win32 程序的自动化功能测试工具