首页 技术 正文
技术 2022年11月14日
0 收藏 484 点赞 4,628 浏览 2297 个字

其中要点,

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

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,996
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,510
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,353
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,137
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,770
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,848