當你瀏覽一個頁面點擊一個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。