javascript应用:Iframe自适应其加载的内容高度
时间:2024-02-25 13:46:07
main.htm:
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=gb2312'>
<meta name='author' content='F.R.Huang(meizz梅花雪)//www.meizz.com'>
<title>iframe自适应加载的页面高度</title>
</head>
<body>
<iframe src="child.htm"></iframe>
</body>
</html>
child.htm:
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=gb2312'>
<meta name='author' content='F.R.Huang(meizz梅花雪)//www.meizz.com'>
<title>iframe 自适应其加载的网页(多浏览器兼容)</title>
<script language=javascript>
function iframeAutoFit()
{
try
{
if(window!=parent)
{
var a = parent.document.getElementsByTagName("IFRAME");
for(var i=0; i<a.length; i++) //author:meizz
{
if(a[i].contentWindow==window)
{
var h = document.body.scrollHeight;
if(document.all) {h += 4;}
if(window.opera) {h += 1;}
a[i].style.height = h;
}
}
}
}
catch (ex)
{
alert("脚本无法跨域操作!");
}
}
if(document.attachEvent) window.attachEvent("onload", iframeAutoFit);
else window.addEventListener('load', iframeAutoFit, false);
</script>
</head>
<body>
<div style="width: 200; height: 400; background-color: yellow">
iframe 自适应其加载的网页(多浏览器兼容)
</div>
</body>
</html>
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python调用Windows API函数编写录音机和音乐播放器功能
![](https://img.aspxhome.com/file/2023/7/76707_0s.jpg)
js 轮播效果实例分享
Python 3.8 新功能大揭秘【新手必学】
![](https://img.aspxhome.com/file/2023/2/90532_0s.jpg)
Python实现解析命令行参数的常见方法总结
![](https://img.aspxhome.com/file/2023/0/61440_0s.png)
Python实现约瑟夫环问题的方法
ASP.NET Core中的Configuration配置二
![](https://img.aspxhome.com/file/2023/8/122778_0s.jpg)
opencv python模糊影像检测效果
![](https://img.aspxhome.com/file/2023/6/80716_0s.jpg)
python+selenium对table表和分页处理
![](https://img.aspxhome.com/file/2023/8/134948_0s.png)
Python3操作SQL Server数据库(实例讲解)
![](https://img.aspxhome.com/file/2023/3/121363_0s.png)
PHP简易延时队列的实现流程详解
ASP所有的Session变量获取实现代码
python实现通过队列完成进程间的多任务功能示例
![](https://img.aspxhome.com/file/2023/9/95589_0s.png)
使用python计算方差方式——pandas.series.std()
ACCESS中Field对象的标题属性
pytorch学习教程之自定义数据集
![](https://img.aspxhome.com/file/2023/6/117396_0s.png)
Python Pandas如何获取和修改任意位置的值(at,iat,loc,iloc)
网页设计者应当注意九大要点
ASP模拟MVC模型的编程方式
Python干货实战之八音符酱小游戏全过程详解
![](https://img.aspxhome.com/file/2023/6/117846_0s.png)