a标签属性 rel="noopener noreferrer"

mac2026-05-17  6

Links using target=’_blank’ gain partial access to the linking page via the window.opener object.

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

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

rel=noopener 新特性

在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。

最新回复(0)