Coding時出現(xiàn)一個錯誤:
error Using target="_blank" without rel="noopener noreferrer" is a security risk: see https://mathiasbynens.github.io/rel-noopener react/jsx-no-target-blank
原因是:為了防止釣魚事故,我們需要將外鏈中的window.opener置為null。
方法一:
a標(biāo)簽設(shè)置target="_blank"屬性時,額外設(shè)置屬性rel="noopener norefferrer"
方法二:
使用window.open(url)打開外鏈時,同時清空新窗口的window.opener和window.location
var otherWindow = window.open();
otherWindow.opener = null;
otherWindow.location = url;
參考:
http://www.itdecent.cn/p/c8319e095474
https://mathiasbynens.github.io/rel-noopener/#hax