Iframe 高度自适应 example (跨子域实现)
2024-09-27 19:48:11
跨子域的iframe高度自适应
比如 'https://www.kzwr.com/topics/baidu' 嵌入了 'http://pan.kzwr.com/',这种跨子域的页面,实现起来也比较简单,看下面的详细代码:
<!doctype html>
<html >
<head>
<title>iframe 自适应高度测试</title>
<style>
iframe{
background-color:aquamarine;
width:100%
}
</style>
</head> <body>
<iframe src="./index1.html" frameborder="0" id="ifr"></iframe>
</body>
</html>
<!doctype html>
<html>
<head>
<title>hello</title>
<style>
#one {
width: 100px;
height: 1110px;
background-color: #ff6a00;
}
</style>
</head>
<body>
<div id="one"> </div>
<script>
// 计算页面的实际高度,iframe自适应会用到
//www.kzwr.com 欢迎朋友们前来交流
function calcPageHeight(doc) {
var cHeight = Math.max(doc.body.clientHeight, doc.documentElement.clientHeight)
var sHeight = Math.max(doc.body.scrollHeight, doc.documentElement.scrollHeight)
var height = Math.max(cHeight, sHeight)
return height
}
window.onload = function () {
var height = calcPageHeight(document)
parent.document.getElementById('ifr').style.height = height + 'px'
}
</script>
</body>
</html>
最新文章
- AWS系列之三 使用EBS
- 《MySchool数据库设计优化》内部测试
- Linux tcpdump 命令详解
- TypeError: &#39;stepUp&#39; called on an object that does not implement interface HTMLInputElement.
- js:数据结构笔记12--排序算法(2)
- asp.net MVC开发过程中,使用到的方法(内置方法及使用说明)
- Java链式方法 连贯接口(fluent interface)
- mybatis0202 一对一查询 resultType实现
- MVC MVC 路由详解
- Hive操作之HQL语句
- Next Greater Element I
- RLP
- JAVA动态代理机制解析
- Dynamics CRM2013/2015 禁止欢迎界面(Disable the Welcome Screen)
- itchat和wordcloud对微信好友的签名进行画像
- Java中BufferedReader到底是一个什么类?
- Selenium vs TestStudio,Selenium Grid vs F2Test
- hive 索引
- 〖Network〗一行命令创建 http-server
- IIS 配置1