跨域产生的原因,及判断条件

1、同源策略

同源策略是浏览器的行为,是为了保护本地数据不被JavaScript代码获取回来的数据污染,因此拦截的是客户端发出的请求回来的数据接收,即请求发送了,服务器响应了,但是无法被浏览器接收

参数原因:

由 Netscape 公司 1995 年引入浏览器,它是浏览器最核心也最基本的安全功能,现在所有支持 JavaScript 的浏览器都会使用这个策略。如果缺少了同源策略,浏览器很容易受到 XSS、 CSFR 等攻击。

2、跨域

跨域就是非同源策略请求。

产生原因:请求方式、域名、端口 其中任意一个不同即为跨域:

url 说明 是否跨域

http://www.abc.com:80/index.html

http://www.abc.com:80/index.asp

同请求方式

同域名

同端口

http://www.abc.com:80/index.html

http://www.abc.com:80/posts/index.html

同请求方式

同域名

同端口

http://www.abc.com:80/index.html

http://www.abc.com:8080/index.html

 

同请求方式

同域名

不同端口

 是

http://www.abc.com:80/index.html

https://www.abc.com:80/index.html

 

不同请求方式

同域名

同端口

 是

http://www.abc.com:80/index.html

http://wap.acb.com:80/index.asp

 

同请求方式

不同域名

同端口

 是
 

http://www.abc.com:80/index.html

http://www.doc.abc.com:80/index.html

 

同请求方式

不同域名

同端口

 是
 

http://www.abc.com:80/index.html

http://192.168.1.2:80/index.html

 

同请求方式

不同域名

同端口

 是

那么为什么有的网页还能各种跳转呢?

原因是:
<ink>、< script>、<img>、< frame>等这些标签具有跨域特性,可以直接访问

原文地址:https://www.cnblogs.com/easyidea/p/14365467.html