其中要点,

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; }

最新文章

  1. web安全性测试用例
  2. winform label文本转换为图片 、Picturebox+label合并转换为图片
  3. 傻瓜式十分钟免费开启 HTTPS,是时候为你的站点加上小绿锁了
  4. hadoop2.0单机安装
  5. AWS AutoScaling
  6. SQLServer中临时表与表变量的区别分析
  7. 算法杂货铺——分类算法之朴素贝叶斯分类(Naive Bayesian classification)
  8. ios8中的UIScreen
  9. [Javascript] Ex: concatAll, map and filter
  10. CoFun 1612 单词分组(容斥)
  11. java——推断日期是否在今天之前
  12. python基础之 正则表达式,re模块
  13. Replace To Make Regular Bracket Sequence
  14. Vim常用的命令
  15. Java 枚举 的学习
  16. nodejs导出excel
  17. 大智慧F10离线资料压缩包带F10关键字过滤软件--更新于2014-01-06.rar 184MB
  18. C#数据库连接方法
  19. Spark向HDFS中存储数据
  20. Linux-数据库2

热门文章

  1. C++深度解析教程学习笔记(6)对象的构造和销毁
  2. jenkins 学习记录2
  3. 关于linux创建用户的有趣事情!
  4. NMS:Non-maximum Suppression学习笔记
  5. docker 制作本地镜像
  6. mysql如何进行以=分割的字符串的拆分
  7. 从官网下载jdk1.6 1.7
  8. 使用Maven构建多模块企业项目
  9. Linux ekho
  10. Smarty3——从配置文件获取的变量