zoukankan      html  css  js  c++  java
  • document.domain 跨域实现

     1 <!DOCTYPE html>
     2 <html>
     3 <head>
     4 <meta charset='utf-8'/>
     5     <title>document.domains</title>
     6 </head>
     7 <body>
     8 <p>我是www页面</p>
     9 <iframe src="http://test.mzk.com/domains.html" id='ifm'></iframe>
    10 </body>
    11     <script type="text/javascript">
    12     document.domain='mzk.com';
    13         function alt(){
    14             
    15         }
    16     var ifm=document.getElementById('ifm');
    17     ifm.onload = function(){
    18     var doc = ifm.contentDocument || ifm.contentWindow.document;
    19     // 在这里操纵b.html
    20     doc.getElementById('btn').onclick=function(){
    21         alert('我是www页面');
    22     }
    23 };
    24     </script>
    25 </html>

    上面是http://www.mzk.com/damains.html;

     http://test.mzk.com/domains.html页面是:

     1 <!DOCTYPE html>
     2 <html>
     3 <head>
     4 <meta charset='utf-8'/>
     5     <title>document.domains</title>
     6 </head>
     7 <body>
     8 <input type="button" class="btn" id="btn" value="按钮" >
     9 </body>
    10     <script type="text/javascript">
    11     document.domain='mzk.com';
    12     </script>
    13 </html>
  • 相关阅读:
    【算法】 冒泡排序
    【算法】 插入排序
    【算法】 斐波那契数列
    【C#】 RBAC 权限框架
    【jQuery】 实用 js
    【jQuery】 Ajax
    【jQuery】 常用函数
    【jQuery】 资料
    【jQuery】 效果
    Linaro/Yocto/Openwrt
  • 原文地址:https://www.cnblogs.com/mk2016/p/5530900.html
Copyright © 2011-2022 走看看