相关属性列举:
noopener | ? ? ? Instructs the browser to open the link without granting the new browsing context access to the document that opened it — by not setting the?Window.opener?property on the opened window (it returns?null ).
? ? ?This is especially useful when opening untrusted links, in order to ensure they cannot tamper? with the originating document via the?Window.opener?property (see?About rel=noopener?for? more details), while still providing the?Referer ?HTTP header (unless?noreferrer ?is used as?well). ? ? ?Note that when?noopener ?is used, nonempty target names other than?_top ,?_self ,? ? ? ? ? ? and?_parent ?are all treated like?_blank ?in terms of deciding whether to open a new? window/tab. | | noreferrer | Prevents the browser, when navigating to another page, to send this page address, or any other value, as referrer via the?Referer: ?HTTP header. (In Firefox, before Firefox 37, this worked only in links found in pages. Links clicked in the UI, like "Open in a new tab" via the contextual menu, ignored this). | | opener ? | Reverts implicit?rel="noopener" ?addition on links with?target="_blank" ?(See?related HTML spec discussion,?WebKit change, and?Firefox bug discussion). | |
如果你需要用a标签打开一个网页:
如果你需要用 a 标签打开一个标签页时,
你会使用 target='_blank' 这个属性,
此时你需要添加 rel='noreferrer noopener'
1.?使用rel=noopener
为了防止window.opener被滥用,在使用targrt=_blank时需要加上rel=noopener
<a href="www.baidu.com" target="_blank" rel="noopener" >
2. rel=norefferrer
rel=noopener支持chrome49和opera36,不支持火狐,为了兼容需要加上rel=noreferrer
<a href="www.baidu.com" target="_blank" rel="noopener norefferrer" >
?总之,加这两个属性目的很简单:为了网络安全!!!?
?养成好的习惯,注意细节。一起加油!!!
|