默认情况下当在页面中打开新页面的时候,新的浏览上下文会对来源页窗口有控制权限 window.opener ,通过该属性可以实现跳转来源页窗口的地址。
A页面代码:
<a href="B页面地址" target="_blank" >链接</a>
B页面代码:
if (window.opener) {
window.opener.location = https://www.abcdefg.com/dykimy;
}
当用户从A页面跳转到B页面的时候,A页面将会自动跳转到 https://www.abcdefg.com/dykimy这就实现了某些黑帽的目的。
如何应对这种流氓的B页面呢?
只需要将A页面代码改为如下即可:
<a href="B页面地址" target="_blank" rel="noopener">链接</a>
noopener 作用:指示浏览器打开链接而不授予新的浏览上下文对打开它的文档的访问权限-通过在打开的窗口中不设置 window.opener 属性(返回 null )。