参考:维基百科-根域https://en.wikipedia.org/wiki...浏览器同源策略及规避方法-阮一峰http://www.ruanyifeng.com/blo...window.name跨域实现原理及实例http://blog.csdn.net/qq_34099...html5postMessage官方APIhttps://developer.mozilla.org...JSONP(直接跳转到JSONP节)http://kb.cnblogs.com/page/13...跨域资源共享CORS详解-阮一峰http://www.ruanyifeng.com/blo...跨域资源共享(CORS))-阿里云技术文档https://www.alibabacloud.com/...1基本概念1.1域名&域名域名:.根域名,.org顶级域名(一级域名),.baidu.com二级域名域名域名:baidu.com顶级域名(一级域名),www.baidu.com二级域名1.2同源策略&跨域同源条件:同协议,同域名,同端口,不满足则为跨域同源目的:浏览器同源策略保证用户信息安全,防止恶意网站窃取数据。1.3限制在很多文章中介绍,跨域限制会对以下三种行为进行限制:1)cookie、localStorage、indexedDB2)dom3)ajax请求我理解按以下分类比较合理:1)cookie2)iframe/window.open(localStorage,indexedDB,dom)3)ajax请求cookie身份授权分离型localStorage,indexedDB,dom跨域限制,一般发生在iframe或window.open中,当满足跨域要求时,newpage获取不到,自然不可能访问window.localStorage、window.indexedDB、document.getElementByIdajax来请求单个类。2实现跨域2.1document.domain浏览器通过设置document.domain来允许跨子域。如果有两个子域,a.example.com和b.example.com,设置document.domain=example.com或Set-Cookie:key=value;domain=example.com;path=/即可实现交叉domainbetweentwosecondarydomains可以解决cookie、iframe、window.open、ajax2.2URL的跨域问题#hash+hashChange事件监听可以解决iframe的跨域问题。不推荐。例如,angular.ui.router的前端路由组件会使用URL#hash字段。2.3window.name可以解决iframe的跨域问题如何监听window.name的变化是个问题,可以存储2M左右的内容2.4html5postMessage+message事件监听可以解决iframe&window的跨域问题.open语法:otherWindow。postMessage(消息,targetOrigin,[传输]);官方API参考2.5ajax-JSONP参考:http://kb.cnblogs.com/page/13...实现原理:在网页调用js文件时,不受同源策略的影响,标签与src属性具有跨域能力,如
