HTML------a标签target_blank使用rel=noopener的场景

相关属性列举:

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.

noreferrerPrevents 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 discussionWebKit 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" >

 总之,加这两个属性目的很简单:为了网络安全!!! 

 养成好的习惯,注意细节。一起加油!!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

绝世唐门三哥

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值