这次给大家带来jquery实现iframe自适应高宽的方法,jquery实现iframe自适应高宽的注意事项有哪些,下面就是实战案例,一起来看一下。
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>
jquery库实现iframe自适应内容高度和宽度
相信看了本文案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章!
推荐阅读:
以上就是jquery实现iframe自适应高宽的方法的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号