1、跨域访问页面,
需要访问后台的页面,通过后台调转
2、跨域自适应宽高

 
思路:通过相互嵌套,获取跨域页面的高度,通过src传回到本域,通过parent方法设置主页的iframe的高度
  • index.jsp 本域
var ifr_el = document.getElementById("content");
function getIfrData(data){
//console.log("index:"+data);
if(oldHeight!=data){
oldHeight=data;
ifr_el.style.height = data+"px";
}
}
  • B.jsp 跨域
<%@include file="/static/iot/proxybase.html"%>
<iframe id="iframe_proxy" src="http://192.16.199.10:8060/Puriew/static/iot/middle.html#0" width="0" style="display: none;"></iframe>
<script>
var oldHeight_proxy = 0,
ifr_el = document.getElementById("iframe_proxy");
t_proxy && clearInterval(t_proxy);
var t_proxy = setInterval(function(){
var height_proxy = $("#body_1").height();//获取body的高度,跨域情况下document.body.scrollHeight;获取的是ifream设定之后的高度
//console.log("proxy: \t"+height_proxy+"\t oldHeight_proxy:"+oldHeight_proxy);
if(oldHeight_proxy != height_proxy) {
oldHeight_proxy = height_proxy;
ifr_el.src += '#' +height_proxy;
}
},200);
</script>
  • middle.jsp 本域
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<script>
var oldHeight_middle = 0;
t_middle && clearInterval(t_middle);
var t_middle = setInterval(function(){
var height_middle = location.href.split('#')[location.href.split('#').length-1];
if(height_middle && height_middle != oldHeight_middle) {
console.log("middle:"+oldHeight_middle)
oldHeight_middle = height_middle;
if(window.parent.parent.parent.getIfrData) {
window.parent.parent.parent.getIfrData(oldHeight_middle);//传到index.jsp 本域
}
}
},200);
</script>
</body>
</html>
 
 
参考链接:
iframe之间通信问题及iframe自适应高度问题 http://www.cnblogs.com/tugenhua0707/p/3346522.html

最新文章

  1. python学习笔记(字符串操作、字典操作、三级菜单实例)
  2. Hibernate之HQL添加过滤器查询的用法
  3. iOS_常用C语言函数
  4. SGA(System Global Area)
  5. 转载:js动态获取图片长宽尺寸(兼容所有浏览器,速度极快)
  6. Struts2文件下载浅析
  7. 在SrollView中嵌套GridView或ListView(转)
  8. JVM学习001通过实例总结Java虚拟机的运行机制
  9. [国嵌攻略][109][Linux系统调用]
  10. win7 wifi热点设置
  11. Spring Boot 面试题
  12. avalonjs学习笔记之实现一个简单的查询页
  13. 移动端无法复制:使用clipboard.js碰到的一个小问题
  14. 解决了好几天的关于django xadmin后台增加链接并执行函数的问题
  15. 关于测绘软件南方CASS(7.0)成图系统的使用心得
  16. 对于目标识别的一些idea-传递特征的position而不是特征或特征图
  17. jQuery基础【1】
  18. javascript版format函数,方便实现复杂字串连接
  19. php解析word,获得文档中的图片
  20. ShaderLab内置变量

热门文章

  1. oracle 删除用户命令和部分表空间操作
  2. Loadrunner11打开WebTours只显示头部解决办法
  3. macbook pro 下eclipse配置svn插件
  4. 【POI 2006】 Tet-Tetris-3D
  5. Laravel实践-自定义全局异常处理
  6. pair运用
  7. WebService安全解决方案—简单握手协议
  8. servlet 3 文件上传
  9. 自定义HTML中select控件
  10. 洛谷 - P1309 - 瑞士轮 - 归并排序