此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。

View in English Always switch to English

FragmentDirective

Baseline 2025
Newly available

Since March 2025, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.

实验性: 这是一项实验性技术
在将其用于生产之前,请仔细检查浏览器兼容性表格

FragmentDirective 接口是用于特性检测的对象,即用来判断浏览器是否支持文本片段。

可通过 Document.fragmentDirective 属性访问。

实例属性

无。

实例方法

无。

示例

在支持该特性的浏览器中打开一个包含一个或多个匹配的文本片段的标签页,并尝试在其开发者工具中运行以下代码:

js
document.fragmentDirective;
// 如果支持则返回空的 FragmentDirective 对象,否则返回 undefined

此功能目前主要用于特性检测。未来 FragmentDirective 对象可以包含更多信息。

规范

Specification
URL Fragment Text Directives
# fragmentdirective

浏览器兼容性

参见