9种跨域方式实现原理

原文约13100字,阅读约需32分钟。发表于:

当协议、子域名、主域名、端口号中任意一个不相同时,都算作不同域。不同域之间相互请求资源,就算作“跨域”。

跨域是指不同域之间相互请求资源时,浏览器会拦截结果,解决跨域的方案有JSONP、CORS、postMessage、websocket、Node中间件代理、nginx反向代理和window.name + iframe、location.hash + iframe等。其中,window.name + iframe和location.hash + iframe可以通过中间页面实现跨域通信,绕过浏览器的跨域访问限制,安全又高效。

相关推荐 去reddit讨论