在a标签里面增加rel="noopener noreferrer"有什么用?
2020-01-22 08:03:25 JST |
Web Design |
3k+ Reads
Copyright Notice: This article is an original work licensed under the CC 4.0 BY-NC-ND license.
If you wish to repost this article, please include the original source link and this copyright notice.
Source link: https://v2know.com/article/134
简单来讲,这样做是为了防止钓鱼网站[1] 。
你的页面如果不加上这个rel="noopener"会被人链接到别的网站,而noreferrer是一些旧浏览器的规范。
一般情况下,这两个合并使用,例如:
<a href="www.baidu.com" target="_blank" rel="noopener noreferrer"></a>
原理
[2]
网页A:
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<a href="window_open.html" target="_blank" >test</a>
</body>
</html>
网页B:
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<script type="text/javascript">
window.opener.location.href = "https://www.baidu.com"
</script>
</body>
</html>
从网页A跳到网页B,你不会跳到网页B,你会跳到百度。
是的,我们利用了window.opener的权限让你实现了跳转,这是老浏览器的一个BUG[3] ,现在用rel="noopener"来拒绝opener权限,
旧的浏览器,可以使用 rel=noreferrer,它不仅禁用了 window.opener,后一个页面也无法获取到 referrer,
使用 rel=noreferrer 可以禁用HTTP头部的Referer属性。
另外,还可以利用 js 来打开新的页面,之后将 opener 置为 null 来完成这个功能[4] 。
需要注意的一点:
绝对不要在内部链接上使用rel= " noreferrer "属性,它会打乱你的谷歌分析报告[5] 。
因为这个属性特性是,不让其他站点知道您正在链接到它。
举个例子,知乎里面的外链通常会被加上noreferrer和nofollow,这两个的作用分别是
①noreferrer是为了不分散网站权重,声明该外链的内容非本站内容。
②nofollow让百度蜘蛛不要对这个外链进行探索。
一般我们给a标签增加
target="_blank" rel="nofollow noreferrer"
或者
target="_blank" rel="nofollow noreferrer noopener"
来标记外链。
参考文档:
[1] rel="noopener noreferrer"
[2] a标签使用rel=noopener
[3] 聊聊 rel=noopener
[4] rel=noopener 新特性
[5] rel = " noreferrer "是什么?
This article was last edited at 2020-11-16 00:14:41 JST
Related Articles
Website Rebuild & Patch Notes
After months of planning and development, I'm excited to share the fully rebuilt version of my website. This update marks a major shift in both design and architecture — moving away from the legacy ASP.NET Core 2.1 MVC framework to a modern .NET 8 Blazor Web App, combining both Blazor Server and WebAssembly. In this post, I’ll highlight the
2025-03-24 15:32:25 JST
|
Web Design
|
124 reads How to do blog donation function?
About CSS: The total number of images replaced is 3, which are quotation marks, radio1 and radio2 images The. Content class may conflict with your CSS. It is necessary to modify your style About JavaScript: No change required
2020-07-03 00:57:07 JST
|
Web Design
|
2k reads 博客打赏功能制作(附源码)及详细说明
关于CSS: 图片替换总数为3张,分别为引号、radio1、radio2图片 .content类可能与你的CSS冲突,有必要修改你的样式 关于JavaScript: 无需改动 关于HTML: alipay.jpg\wechat.jpg\alipayimg.png\wechatimg.png\close.jpg 要准备好 注意裁剪二维码,大小为140*140px
2020-06-13 18:23:18 JST
|
Web Design
|
2k reads Why not recommend you to use Blogger in 2020 (Specially for programmers)
As a programmer, I recommend that you write a blog yourself instead of using blogger. A few days ago, I used Blogger and I found its editor very difficult to use. Because I am a programmer, I need to paste the code, but the display of the code in Blogger is very bad. For example, the style I thought would work, but it didn't work on Blogger. I think the CSS style has been overwritten. So I opened
2020-12-14 16:46:06 JST
|
Web Design
|
2k reads 仿CSDN侧边栏滚轮响应脚本
这是本网站使用的,仿CSDN侧边栏滚轮响应脚本,需要先引入Jquery配合使用
2020-01-24 22:01:37 JST
|
Web Design
|
1k reads 关于pcrdfans的网页元素分析
//20 $('#battle_chara_select > div > div:nth-child(1) > div.ant-collapse-content.ant-collapse-content-active > div').children().length; //17 $('#battle_chara_select > div > div:nth-child(2) > div.ant-collapse-content.ant-collapse-content-active > div').children().length
2020-09-03 03:58:42 JST
|
Web Design
|
1k reads