重点分析:

主域名页面:页面A,页面C

其它域名页面:页面B

步骤:

1、页面A(主域名)通过Iframe(id="iframeB")嵌套页面B(其它域名)

2、页面B(其它域名)获取自身高度值pageB_height,再通过Iframe(id="iframeA")嵌套页面C同时传自身高度值pageB_height给页面C

3、因为页面C和页面A同域名,所以可以在页面C中获取页面A的Iframe(id="iframeB"),并将页面A中的iframeB的高度值设为pageB_height

中间页面C(主域名):http://www.main.com/setheight.aspx

<html><head><title>JavaScript使跨域Iframe自动适应高度中间页面</title>
<script type="text/javascript">
function pseth() {
var iObj = window.parent.parent.document.getElementById('iframeB'); //A和main同域,所以可以访问节点
var iObjH = "";
try {
iObjH = window.parent.parent.frames["iframeB"].frames["iframeA"].location.hash; //访问自己的location对象获取hash值
} catch (e) {
iObjH = window.location.toString();
} var arr = iObjH.split("#")[1];
var arrPasearr = arr.split("|");
// alert(arrPasearr[0]);
iObj.style.height = arrPasearr[0] + "px"; //操作dom if (arrPasearr[1] != undefined && arrPasearr[1] != "")
window.parent.parent.document.title = decodeURI(arrPasearr[1]) + '-吉运商城';
}
try {
pseth();
} catch (e) {
}
</script>
</head><body></body></html>

 //code by:博客园-曹永思 

主页面A(主域名):http://www.main.com/index.aspx

<html><head><title>主页面</title>
</head><body>
<iframe id="iframeB" src="http://b.main.com/index.html" scrolling="no" width="100%" height="1000px" frameborder="0" marginwidth="0" marginheight="0"></iframe>
</body></html>

  

嵌套的页面B(其它域名): http://b.main.com/index.html

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>嵌套在Iframe里的页面</title>
</head>
<body bgcolor="#f1e7de">
<iframe id="iframeA" name="iframeA" src="" width="0" height="0" style="display:none;" ></iframe>
</body>
<script type="text/javascript">
function sethash() {
var hashH = document.documentElement.scrollHeight; //获取自身高度
var urlC = "http://www.main.com/setheight.aspx"; //设置iframeA的src
document.getElementById("iframeA").src = urlC + "#" + hashH + "|"; //将高度作为参数传递
}
window.onload = sethash;
</script>
</html>

  

Iframe跨域JavaScript自动适应高度的更多相关文章

  1. Iframe跨域嵌入页面自动调整高度的办法

    http://www.a.com/A.html http://www.a.com/B.html http://www.a.com/D.js http://www.c.com/C.html A.html ...

  2. 解决Iframe跨域高度自适应,利用window.postMessage()实现跨域消息传递页面高度(JavaScript)

    在iframe跨域引用高度自适应这块写的js方式都试了不管用,最终使用的是window.postMessage() 跨域获取高度 传递信息 1.首先,在主页面上使用iframe引入子页面:也就是A.h ...

  3. javascript跨域、iframe跨域访问

    1.window 对象 浏览器会在其打开一个 HTML 文档时创建一个对应的 window 对象.但是,如果一个文档定义了一个或多个框架(即,包含一个或多个 frame 或 iframe 标签),浏览 ...

  4. IFrame跨域访问自定义高度

    由于JS禁止跨域访问,如何实现不同域的子页面将高度返回给父页面本身,是解决自定义高度的难点. JS跨域访问问题描述:应用A访问应用B的资源,由于A,B应用分别部署在不同应用服务器(tomcat)上,属 ...

  5. IFrame跨域访问&&IFrame跨域访问自定义高度

    1.IFrame跨域访问: http://blog.csdn.net/fdipzone/article/details/17619673 2.IFrame跨域访问自定义高度: 由于JS禁止跨域访问,如 ...

  6. 关于iFrame特性总计和iFrame跨域解决办法

    1.iframe 定义和用法 iframe 元素会创建包含另外一个文档的内联框架(即行内框架). HTML 与 XHTML 之间的差异 在 HTML 4.1 Strict DTD 和 XHTML 1. ...

  7. CP="CAO PSA OUR" 用P3P header解决iframe跨域访问cookie

    1.IE浏览器iframe跨域丢失Session问题 在开发中,我们经常会遇到使用Frame来工作,而且有时是为了跟其他网站集成,应用到多域的情况下,而Iframe是不能保存Session的因此,网上 ...

  8. js iframe跨域访问

    1.什么是跨域? 2.前台解决跨域几种方法 2.1 动态创建script 2.2 使用document.domain 2.3使用HTML5新属性postMessage 2.4 利用iframe和loc ...

  9. JS跨域(ajax跨域、iframe跨域)解决方法及原理详解(jsonp)

    这里说的js跨域是指通过js在不同的域之间进行数据传输或通信,比如用ajax向一个不同的域请求数据,或者通过js获取页面中不同域的框架中(iframe)的数据.只要协议.域名.端口有任何一个不同,都被 ...

随机推荐

  1. MYSQL 优化常用方法总结

    1, 选取最合适的字段属性以及长度 MySQL可以很好的支持大数据量的存取,但是一般说来,数据库中的表越小,在它上面执行的查询也就会越快. 比如:定义邮政编码 char(6) 最合适,如果char(2 ...

  2. Python中的 __all__和__path__ 解析

    https://blog.csdn.net/u012450329/article/details/53001071

  3. HSTS

    一.简介   二.部署   三.其他 1)利用 HSTS 安全协议柔性解决全站HTTPS 的兼容性问题 http://www.toutiao.com/a6383719177903833346/

  4. html与css关系

    1.html是网页的内容的载体 内容是作者发在页面想让用户浏览的信息,包括文字,图片,视频等 2.css样式是表现 像网页的外衣,比如标题字体的变化,颜色的变化,背景颜色,边框等,所有这些都是用来改变 ...

  5. iOS.GetCurrentTimestamp

    Cocoa 中测量时间的方法 1. The Methods to Get Current Timestamp iOS中获取时间戳的方法: A. CACurrentMediaTime() B. gett ...

  6. Tinyos学习笔记(三)

    读取Telosb内部传感器数据,并在计算机上显示. senseC.nc代码如下: #include "Timer.h" #include "sense.h" # ...

  7. 语法分析器初步学习——LISP语法分析

    语法分析器初步学习——LISP语法分析 本文参考自vczh的<如何手写语法分析器>. LISP的表达式是按照前缀的形式写的,比如(1+2)*(3+4)在LISP中会写成(*(+ 1 2)( ...

  8. Writing modular applications with laravel-modules

    01-07-2016 Let me start by saying Laravel is an amazing framework. However when it comes to writing ...

  9. Spring ApplicationContext(一)初始化过程

    Spring 容器 ApplicationContext(一)初始化过程 Spring 系列目录(https://www.cnblogs.com/binarylei/p/10198698.html) ...

  10. 【UI测试】--易用性