为什么会有跨域?那必须得说同源政策,同源指的是三个同源:1,协议相同,域名相同,端口相同,例如http://y.localhost.com:7001/public/3.html;这些网址协议是http://域名是y.localhost.com:,端口号是7001,在这三个都相同的话就是同源
同源:http://y.localhost.com:7001/public/5.html,
同域不同端口http://y.localhost.com:7002/public/3.html,
协议不同https://y.localhost.com:7001/public/3.html
域不同http://x.localhost.com:7001/public/3.html,
不同源的网址不能不可以共享cookie,LocalStorage ,dom也无法获取,ajax不能发送,防止了恶意的网站窃取数据,保证了用户信息的安全,所以同源政策是必须的,
但是也给开发人员带来了不便。那解决同源政策有这几种方法:
1.window+哈希值+iframe
http://y.localhost.com:7001/public/1.html页面的js:
var iframe = document.createElement('iframe')
ifram