jquery库实现iframe自适应内容高度和宽度
来源:互联网 发布:企业级it 编辑:程序博客网 时间:2024/05/17 08:59
javascript原生和jquery库实现iframe自适应内容高度和宽度---推荐使用jQuery的代码!
<iframe src="index.php" id="mainiframe" name="mainiframe" width="100%" frameborder="0" scrolling="no" marginwidth="0" marginheight="0"></iframe>
基于Jquery库的代码很好实现:
<script language="javascript" type="text/javascript">
$(document).ready(function(){
$("#mainframe").load(function(){
$(this).height(0); //用于每次刷新时控制IFRAME高度初始化
var height = $(this).contents().height() + 10;
$(this).height( height < 500 ? 500 : height );
});
});
</script>
基于JS原生代码的实现:
<script language="javascript">
if (window.parent.length>0){window.parent.document.all.mainframe.style.height=document.body.scrollHeight;}
</script>
只需在你被iframe调用的文件</body>之后加入上面这段即可!
这个也可以控制iframe的高度随内容的多而自动增长
<iframe name="web" width="100%" frameborder=0 height="100%" src="index.php" id="web" onload="this.height=web.document.body.scrollHeight+20" ></iframe>
<iframe src="index.php" id="mainiframe" name="mainiframe" width="100%" frameborder="0" scrolling="no" marginwidth="0" marginheight="0"></iframe>
基于Jquery库的代码很好实现:
<script language="javascript" type="text/javascript">
$(document).ready(function(){
$("#mainframe").load(function(){
$(this).height(0); //用于每次刷新时控制IFRAME高度初始化
var height = $(this).contents().height() + 10;
$(this).height( height < 500 ? 500 : height );
});
});
</script>
基于JS原生代码的实现:
<script language="javascript">
if (window.parent.length>0){window.parent.document.all.mainframe.style.height=document.body.scrollHeight;}
</script>
只需在你被iframe调用的文件</body>之后加入上面这段即可!
这个也可以控制iframe的高度随内容的多而自动增长
<iframe name="web" width="100%" frameborder=0 height="100%" src="index.php" id="web" onload="this.height=web.document.body.scrollHeight+20" ></iframe>
阅读全文
0 0
- jquery库实现iframe自适应内容高度和宽度
- jquery库实现iframe自适应内容高度和宽度
- jquery库实现iframe自适应内容高度和宽度
- iframe自适应高度和宽度
- iframe自适应宽度和高度
- iframe自适应高度和宽度
- iframe 自适应宽度和高度
- iframe自适应高度和宽度 全css实现无javascript
- iframe自适应高度和宽度 全css实现无javascript
- jquery 实现iframe 自适应高度
- jquery 实现iframe 自适应高度
- JQuery实现iframe自适应高度
- jquery 实现iframe 自适应高度
- jquery 实现iframe 自适应高度
- jquery 实现iframe 自适应高度
- jquery 实现iframe 自适应高度
- jquery实现iframe自适应高度
- Jquery 实现iframe 自适应高度
- JVM调优总结 -Xms -Xmx -Xmn -Xss
- iOS在应用内显示App的详情以及评分内容
- 含有return的try catch finally 异常嵌套测试总结
- 前端面试题(2017-12-3)
- 类的const成员函数的调用问题
- jquery库实现iframe自适应内容高度和宽度
- 机器学习系列(1)_逻辑回归初步
- Scrapy1.4中文文档
- JAVAjdk目录结构简单介绍
- cmd命令导入导出Oracle数据库
- 前端面试题(2017-12-4)
- 杂记
- Kotlin学习(一)—— IDEAIntelliJ IDEA的安装配置及Kotlin的环境部署
- 在公司充当多个角色,并能对外很好的切换