JQuery IFrame框架高度自适应(支持嵌套–兼容IE,ff,safafi,chrome)
来源:互联网 发布:m56头盔知乎 编辑:程序博客网 时间:2024/05/22 02:06
在网上找了很多的iframe自适应高度的脚本,找到了比较好的
jquery很强大,代码很简单:
$("#iframe_1").load(function() {
$(this).height($(this).contents().height());
})
Index.hmtl
<!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">
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
</head>
<body>
<div style="height:200px"></div>
<iframe id="iframe_1" src="iframe-inside-content.html" width="100%" border="2" scrolling="no"></iframe>
<script type="text/javascript">
$("#iframe_1").load(function() {
$(this).height($(this).contents().height());
})
</script>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
</head>
<body>
<div style="height:200px"></div>
<iframe id="iframe_1" src="iframe-inside-content.html" width="100%" border="2" scrolling="no"></iframe>
<script type="text/javascript">
$("#iframe_1").load(function() {
$(this).height($(this).contents().height());
})
</script>
</body>
</html>
iframe-inside-content.html代码
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script>
function hideDiv(){
$("#content").hide();
$(window.parent.document).find('#iframe_1').height($("#wrap").height());
}
function showDiv(){
$("#content").show();
$(window.parent.document).find('#iframe_1').height($("#wrap").height());
}
</script>
<style>
*{margin:0;paddding:0;}
body{background:transparent;background-color:#eee;height:100%;}
#content{height:1000px;background-color:#ddd;margin:50px;}
</style>
</head>
<body>
<div id="wrap">
<a href="#" onclick="hideDiv();">隐藏DIV</a>
<a href="#" onclick="showDiv();">显示DIV</a>
<div id="content">div content</div>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script>
function hideDiv(){
$("#content").hide();
$(window.parent.document).find('#iframe_1').height($("#wrap").height());
}
function showDiv(){
$("#content").show();
$(window.parent.document).find('#iframe_1').height($("#wrap").height());
}
</script>
<style>
*{margin:0;paddding:0;}
body{background:transparent;background-color:#eee;height:100%;}
#content{height:1000px;background-color:#ddd;margin:50px;}
</style>
</head>
<body>
<div id="wrap">
<a href="#" onclick="hideDiv();">隐藏DIV</a>
<a href="#" onclick="showDiv();">显示DIV</a>
<div id="content">div content</div>
<div>div2222 content</div>
</div>
</div>
</body>
</html>
开始找到代码的时候直接下载到本地去测试,发现谷歌浏览器是不行的。 protocols and ports must match. 这种错误,于是查了下,发现貌似是跨域问题,把他们拿到服务器上 用地址去访问就可以了,也就是说谷歌浏览器对file:///C:/Users/xx.xx/Desktop/index.html 认为file:///C:/Users/xx.xx/Desktop/iframe-inside-content.html 不是同域的。
- JQuery IFrame框架高度自适应(支持嵌套–兼容IE,ff,safafi,chrome)
- JQuery IFrame框架高度自适应(支持嵌套–兼容IE,ff,safafi,chrome)
- 跨域iframe高度自适应(兼容IE/FF/OP/Chrome)
- 跨域iframe高度自适应(兼容IE/FF/OP/Chrome)
- 跨域iframe高度自适应(兼容IE/FF/OP/Chrome)
- iframe高度自适应,兼容IE,FF
- 同域及跨域下iframe高度自适应(兼容IE/FF/OP/Chrome)
- IE FF 兼容的IFRAME 自适应高度JS代码
- 真正的iframe高度自适应(兼容IE,FF,Opera)
- iframe页面调用高度自适应方法代码,兼容IE,FF
- iframe IE FF高度自适应
- 让iframe自适应高度(支持XHTML,支持FF)
- iframe自适应高度(支持XHTML,支持FF)
- js实现的非跨域的iframe高度自适应(完美兼容IE,FF,Opera)
- 跨域访问Iframe自适应高度(兼容Firfox,IE)
- Iframe高度自适应(兼容IE/Firefox、同域/跨域)
- Iframe高度自适应(兼容IE/Firefox、同域/跨域)
- Iframe高度自适应(兼容IE/Firefox、同域/跨域)
- 用httpclient-3.1 的android網絡通信
- zz MATLAB 与 C 语言混合编程接口:MEX 函数最简单示例之一
- Oracle编程实现1-100偶数和的实现
- C语言软件规范
- WebView简介(定制基本行为篇)
- JQuery IFrame框架高度自适应(支持嵌套–兼容IE,ff,safafi,chrome)
- .NET设计模式系列文章
- 编程求解不等式组有没有解
- 《概率论与数理统计》历史资料(转)
- Iphone之UIAlertView和UIActionSheet
- 如何编写PHP扩展
- 第四周任务一 三角形
- svn 问题总结
- 120行JavaScript搞定俄罗斯方块