Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【JS跨域问题】 #3

Open
linkun-wang opened this issue Jan 31, 2019 · 0 comments
Open

【JS跨域问题】 #3

linkun-wang opened this issue Jan 31, 2019 · 0 comments

Comments

@linkun-wang
Copy link
Owner

  1. 定义: JavaScript出于安全性考虑,同源策略机制对跨域访问做了限制。域仅仅是通过“URL的首部”字符串进行识别,“URL的首部”指window.location.protocol +window.location.host,也可以理解为“Domains, protocols and ports must match”。实际上,同源策略就是浏览器的一种保护机制,只要请求双方的URL协议、域名(主机)、端口有任何一个不同,都被当作是跨域。

  2. 解决思路:

  • 构造同域,人为将其通信双方设为同一域名下;

  • 规避跨域,使用iframe或动态脚本、其他页面公共对象属性来传值通信

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant