使用window.name 进行数据跨域传递
其中要点,
Stpe1,浏览器在Iframe中加载一个异域的页面,这个页面返回 <script>window.name=”任何数据”</script>,这时候,取 iframe.contentwindow.name是拒绝访问的。
Step2,在Iframe中加载一个本域中的任意页面,此时,iframe.contentwindow.name 就可以访问了,
DEMO: 下面是不修饰的代码,
1: <script type="text/javascript">
2:
3: function getContents(iframe) {
4: try {
5: // Make sure the iframe's window & document are loaded.
6: if (!iframe.contentWindow || !iframe.contentWindow.document) {
7: console.log("no contentwindow");
8: return null;
9: }
10:
11: console.info("window.name=" + iframe.contentWindow.name);
12: // Get the response from window.name
13: return iframe.contentWindow.name;
14: } catch (e) {
15: console.error(e);
16: return null;
17: }
18: }
19:
20:
21: //getContents(this);
22:
23:
24: function test() {
25: var doc = document;
26: var iframe = doc.createElement('iframe');
27: doc.body.appendChild(iframe);
28:
29: var form = doc.createElement('form');
30: doc.body.appendChild(form);
31:
32: var requestId = "__Go";
33: iframe.contentWindow.name = requestId;
34: form.target = requestId;
35: form.action = "http://castest.youxituan.com/cas/JsLogin";
36: form.method = "post";
37: var isFirst;
38: var time = 0;
39: iframe.onload = function () {
40: time++;
41: console.info("time=" + time);
42: if (time == 1) {
43: console.info("first" + iframe.src);
44: iframe.contentWindow.location = 'about:blank';
45:
46: //iframe.contentWindow.document.write(".....");
47: isFirst = false;
48: } if (time == 2) {
49: console.info("not first");
50: window.alert(iframe.contentWindow.name);
51:
52: //iframe.contentWindow.document.write('');
53: //iframe.contentWindow.close();
54: //document.body.removeChild(iframe);
55:
56: //iframe.src = '';
57: iframe = null;
58: }
59: console.log("onload");
60: getContents(iframe);
61:
62: };
63: iframe.onreadystatechange = function () {
64: console.log("onreadystatechange");
65: getContents(iframe);
66: };
67:
68: form.submit();
69: }
70:
71:
72: $(function () {
73: test();
74: });
75:
76:
77: </script>
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
使用window.name 进行数据跨域传递的更多相关文章
- HTML5 window/iframe跨域传递消息 API
原文地址:HTML5′s window.postMessage API 在线示例:Using HTML5's window.postMessage(请打开控制台看日志) 原文日期: 2010年09月0 ...
- javascript跨域传递消息 / 服务器实时推送总结
参考文档,下面有转载[非常好的两篇文章]: http://www.cnblogs.com/loveis715/p/4592246.html [跨源的各种方法总结] http://kb.cnblogs. ...
- window.name实现的跨域数据传输 JavaScript跨域总结与解决办法
原文地址: http://www.cnblogs.com/rainman/archive/2011/02/20/1959325.html#m4 什么是跨域 1.document.domain+ifr ...
- node下的跨域传递cookie
研究背景: 最近有一位朋友找工作,需要面试,涉及到面试就涉及面试题,于是我想起来鄙人之前面试被问到的一个跨域传递cookie的问题.搜索了相关资料,但自己不敲一下肯定是不足以让人信服的. 我用node ...
- window.name实现的跨域数据传输
这篇文章是对 JavaScript跨域总结与解决办法 的补充. 有三个页面: a.com/app.html:应用页面. a.com/proxy.html:代理文件,一般是一个没有任何内容的html文件 ...
- javascript跨域通信(二):window.name实现的跨域数据传输
首先了解一下window.name这个东西是什么. name 在浏览器环境中是一个全局/window对象的属性,当在 frame 中加载新页面时,name 的属性值依旧保持不变 并且name 属性仅对 ...
- ajax请求json数据跨域问题(转)
一.后台代理技术 由服务器端向跨域下的网站发出请求,再将请求结果返回给前端,成功避免同源策略的限制. 具体操作如下: 1.在localhost:81/a.html中,向同源下的某个代理程序发出请求 $ ...
- jsonp实现数据跨域请求
1.我们知道,哪怕跨域js文件中的代码(当然指符合web脚本安全策略的),web页面也是可以无条件执行的. 远程服务器remoteserver.com根目录下有个remote.js文件代码如下: al ...
- 关于前端调用后端php数据跨域的问题
https://blog.csdn.net/qq_21386275/article/details/87269979 js前端 <!DOCTYPE html><html>< ...
随机推荐
- 语法错误 : 缺少“;”(在“*”的前面) 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
sv2010编译的时候遇到错误: error C2143: 语法错误 : 缺少“;”(在“*”的前面) error C4430: 缺少类型说明符 - 假定为 int.注意: C++ 不支持默认 int ...
- sql server生成递归日期、连续数据
WITH Date AS ( SELECT CAST('2008-08-01' AS DATETIME) da UNION ALL FROM Date WHERE da < '2008-08-2 ...
- Python模块及其导入
一.模块 1.模块的定义: 为了编写可维护的代码,我们把很多函数分组,分别放到不同的文件里,这样,每个文件包含的代码就相对较少, 很多编程语言都采用这种组织代码的方式.在Python中,一个.py文件 ...
- SELINUX配置
今天试着将centos7的ssh默认端口改成1234,但改了后,SSHD服务竟然启动不了了.后来关了selinux测试,果然可以了.但这是运行环境,不能关,所以不得不配置semanage! 一.安装s ...
- 2-1 CPU多级缓存-缓存一致性.mkv
- jQuery div鼠标移动效果
<head runat="server"> <meta http-equiv="Content-Type" content="tex ...
- 解决0RA-04031故障
1.客户反应报表数据很慢,简单查询5分钟都出不来. 2.登陆数据库服务器检查日志:Thu Mar 21 16:20:30 2013Errors in file /opt/oracle/diag/rdb ...
- Solidity notes
1. 查询transaction历史记录 https://forum.ethereum.org/discussion/2116/in-what-ways-can-storage-history-be- ...
- xamarin.droid自己的示例工程有些都装不上模拟器,是因为它的architectures选项没设对
也许是版本更迭导致的,有些老工程的architectures不对,如果x86不勾的话,是不能在genymotion的模拟器上跑的.
- 21. Date 函数
SQL 日期 当我们处理日期时,最难的任务恐怕是确保所插入的日期的格式,与数据库中日期列的格式相匹配. 只要数据包含的只是日期部分,运行查询就不会出问题.但是,如果涉及时间,情况就有点复杂了. 在讨论 ...