ToBeBest

当你浏览一个页面点击一个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://blog.csdn.net/howsoever/article/details/79081084

分类:

技术点:

相关文章: