网络编程 
首页 > 网络编程 > 浏览文章

javascript原生和jquery库实现iframe自适应高度和宽度

(编辑:jimmy 日期: 2025/12/28 浏览:3 次 )

javascript原生和jquery库实现iframe自适应内容高度和宽度---推荐使用jQuery的代码!

"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 "htmlcode">
<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="/UploadFiles/2021-04-02/index.php">

jquery库实现iframe自适应内容高度和宽度

上一篇:js清空表单数据的两种方式(遍历+reset)
下一篇:关于javaScript注册click事件传递参数的不成功问题
在去年的5月23日,借助Intel Bridge Technology以及Intel Celadon两项技术的驱动,Intel为PC用户带来了Android On Windows(AOW)平台,并携手国内软件公司腾讯共同推出了腾讯应用宝电脑版,将Windows与安卓两大生态进行了融合,PC的使用体验随即被带入到了一个全新的阶段。