美文网首页
跨域-document.domain

跨域-document.domain

作者: duJing | 来源:发表于2017-01-04 14:48 被阅读204次

上一篇七种跨域方法【1.CROS篇】主要解决的是异域之间的传值 这里主要解决的是子域与父域之间的传值 问题描述: 现有父域:http://b.com/b.com.html 要向子域:http://a.b.com/a.b.com.html获取数据 怎么办? 将document.domain = 'b.com';都设置为父域即可

如果不知道如何配置虚拟主机?
http://blog.csdn.net/super_yang_android/article/details/53991982
父域:http://b.com/b.com.html内容
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<script>
    document.domain = 'b.com';
    var ifr = document.createElement('iframe');
    ifr.src = 'http://a.b.com/a.b.com.html';
    ifr.style.display = 'none';
    document.body.appendChild(ifr);
    ifr.onload = function(){
        var doc = ifr.contentDocument || ifr.contentWindow.document;
        // 这里操作DOM
        var oUl = doc.getElementById('ul1');
        alert(oUl.innerHTML);
        ifr.onload = null;
    };
</script>
</body>
</html>
子域:http://a.b.com/a.b.com.html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    document.domain = 'b.com';
</script>
<ul id="ul1">我是子域a.b.com中的UL</ul>
</body>
</html>

相关文章

  • Js 跨域

    document.domain 可以跨子域

  • 前端如何解决常见跨域问题

    跨域解决方案 1、 通过jsonp跨域 2、 document.domain + iframe跨域 3、 loca...

  • 跨域解决方案

    跨域解决方案 跨域解决方案有:设置document.domain,使用带src标签,JSONP,navigatio...

  • js跨域请求方式

    回答:(1)、通过jsonp跨域;(只能抓去get方式的请求) (2)、通过修改document.domain来跨...

  • 跨域-document.domain

    上一篇七种跨域方法【1.CROS篇】主要解决的是异域之间的传值 这里主要解决的是子域与父域之间的传值 问题描述: ...

  • 14:JS 实现跨域

    JSONP:通过动态创建 script,再请求一个带参网址实现跨域通信。document.domain + ifr...

  • Jsonp --- 利用Jsonp做百度搜索框

    解决浏览器跨域问题的几种方法 flash 服务器代理中转 Jsonp document.domain(针对基础域名...

  • 跨域常见解决方案

    一、设置 document.domain 原理:相同主域名下不同子域页面,通过设置document.domain让...

  • js设置document.domain实现跨域

    document.domain用来得到当前网页的域名。比如在地址栏里输入: 我们也可以给document.doma...

  • 降域

    1.什么是降域 利用document.domain进行降域例如http://a.justfun.me和http:/...

网友评论

      本文标题:跨域-document.domain

      本文链接:https://www.haomeiwen.com/subject/cniovttx.html