Coding时出现一个错误:
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标签设置target="_blank"
属性时,额外设置属性rel="noopener norefferrer"
方法二:
使用window.open(url)
打开外链时,同时清空新窗口的window.opener和window.location
var otherWindow = window.open();
otherWindow.opener = null;
otherWindow.location = url;
参考:
https://www.jianshu.com/p/c8319e095474
https://mathiasbynens.github.io/rel-noopener/#hax
网友评论