a标签属性 rel="noopener noreferrer"

 

  超链接 target="blank" 要增加 rel="nofollow noopener noreferrer" 来堵住钓鱼安全漏洞。如果你在链接上使用 target="blank"属性,并且不加上rel="noopener"属性,那么你就让用户暴露在一个非常简单的钓鱼攻击之下。

当你浏览一个页面点击一个a标签连接 <a href="www.baidu.com" target="_blank"> 跳转到另一个页面时,

在新打开的页面(baidu)中可以通过 window.opener获取到源页面的部分控制权, 即使新打开的页面是跨域的也照样可以(例如 location 就不存在跨域问题)。

rel=noopener 新特性

<a href="www.baidu.com" target="_blank" rel="noopener noreferrer"></a>

在chrome 49+,Opera 36+,打开添加了rel=noopener的链接, window.opener 会为null。在老的浏览器中,可以使用 rel=noreferrer 禁用HTTP头部的Referer属性,使用下面JavaScript代替target='_blank' 的解决此问题:

var otherWindow = window.open('http://keenwon.com');
otherWindow.opener = null;
otherWindow.location = url;

使用 window.open 打开页面,手动把opener设置为null。

不停学习,热爱是源源不断的动力。
原文地址:https://www.cnblogs.com/ximenchuifa/p/14954311.html