> For the complete documentation index, see [llms.txt](https://gitbook.cdxiaodong.life/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gitbook.cdxiaodong.life/web-ying-yong-an-quan/html-zhu-ru/target.md). Agents can also search and read this documentation through its [MCP server](https://gitbook.cdxiaodong.life/~gitbook/mcp).

# target属性注入

## 概述

[target](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a) 属性指定在何处显示链接的URL作为浏览上下文（标签、窗口或 `<iframe>`）的名称。以下关键字对于加载URL的位置有特殊含义：

* `_self` - 当前的浏览上下文，默认值。
* `_blank` - 通常是一个新标签页，但用户可以配置浏览器改为打开新窗口。
* `_parent` - 当前浏览上下文的父级，如果没有父级，行为如同 `_self`。
* `_top` - 最顶层的浏览上下文（当前上下文的"最高"祖先），如果没有祖先，行为如同 `_self`。

## \_blank

使用 `target=_blank` 允许链接页面通过 [window.opener](https://developer.mozilla.org/en-US/docs/Web/API/Window/opener) API 获取对源页面的部分访问权限。新打开的标签页然后可以将 `window.opener.location` 更改为钓鱼页面或在打开者页面上执行JavaScript。

{% hint style="info" %}
在较新的浏览器版本（例如Firefox 79+）中，在 `<a>` 元素上设置target="\_blank"会隐式提供与设置 `rel="noopener"` 相同的 `rel` 行为。
{% endhint %}

## 参考资料

* [Target="\_blank" — 最被低估的漏洞](https://medium.com/@jitbit/target-blank-the-most-underestimated-vulnerability-ever-96e328301f4c)
