跨域,注意是浏览器设置的同源策略,是在浏览器端限制的,也就是在当前域名下发送的xhr请求是否和当前域名同域。
如果跨域了,可以通过设置Access-Control-Allow-Origin来解决跨域;
如果是同域,则cookie自动被带上,如果是跨域,则需要设置withCredentials(chorme浏览器94以前的版本);
如果是在BBB里执行console.log(window.location),则打印的是BBB的location。
同域下不一定能携带cookie??这好像还和samesite有关系
不同域下即使设置withCredentials也不一定能携带cookie
跨站与跨域的区别:
跨域:浏览器的安全策略,协议、域名、端口只要有一个不同就跨域;
跨站:顶级域名+二级域名 不同就跨站;
- X-Frame-Options作用
<div id="pageId" style='height: 400px;'>
<iframe
name="frameName"
allowtransparency="true"
allow="fullscreen"
width="100%"
height="100%"
src='https://www.baidu.com/'
frameBorder='no'
scrolling="no"
></iframe>
</div>
打开百度首页,发现确实设置了该属性
参考:
https://juejin.cn/post/6844904095271288840
跨站(cross-site)、跨域(cross-origin)、SameSite与XMLHttpRequest.withCredentials