跨子域的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>

最新文章

  1. AWS系列之三 使用EBS
  2. 《MySchool数据库设计优化》内部测试
  3. Linux tcpdump 命令详解
  4. TypeError: &#39;stepUp&#39; called on an object that does not implement interface HTMLInputElement.
  5. js:数据结构笔记12--排序算法(2)
  6. asp.net MVC开发过程中,使用到的方法(内置方法及使用说明)
  7. Java链式方法 连贯接口(fluent interface)
  8. mybatis0202 一对一查询 resultType实现
  9. MVC MVC 路由详解
  10. Hive操作之HQL语句
  11. Next Greater Element I
  12. RLP
  13. JAVA动态代理机制解析
  14. Dynamics CRM2013/2015 禁止欢迎界面(Disable the Welcome Screen)
  15. itchat和wordcloud对微信好友的签名进行画像
  16. Java中BufferedReader到底是一个什么类?
  17. Selenium vs TestStudio,Selenium Grid vs F2Test
  18. hive 索引
  19. 〖Network〗一行命令创建 http-server
  20. IIS 配置1

热门文章

  1. 03-24 Winform图表Chart
  2. C# 一维码生成
  3. [转] C#调用外部DLL
  4. delphi 选择文件夹,路径选择,浏览文件夹
  5. 获取properties配置
  6. promtheus 配置文件
  7. C语言清空输入缓冲区的N种方法对比(转)
  8. 自动删除 Elasticsearch 索引
  9. WCF配置Tcp协议
  10. Sqlserver2005中的varchar,varchar,char,nchar的比较