同源策略(Same origin policy)是一种约定,它是浏览器最核心也最基本的安全功能,分为以下两种:

1.DOM 同源策略:禁止对不同源页面 DOM 进行操作。这里主要场景是 iframe 跨域的情况,不同域名的 iframe 是限制互相访问的。

2.XMLHttpRequest 同源策略:禁止使用 XHR 对象向不同源的服务器地址发起 HTTP 请求。

解决方法:

1.CORS(跨域资源共享)

2.JSONP 跨域

3.图像 Ping 跨域

4.服务器代理

5.document.domain 跨域

6.window.name 跨域

7.location.hash 跨域

8.postMessage 跨域