FragmentDirective

基准线 2025
新推出

自 ⁨2025 年 3 月⁩ 起,此功能可在最新的设备和浏览器版本上使用。此功能可能在旧设备或浏览器上无法正常工作。

FragmentDirective 接口是一个公开的对象,允许代码检查浏览器是否支持文本片段(text fragments)

可以通过 Document.fragmentDirective 属性访问它。

实例属性

无。

实例方法

无。

示例

检查是否支持文本片段

下面的代码通过检查 Document.fragmentDirective 是否已定义,来记录你的浏览器是否支持文本片段。请注意,该对象是空的,目前主要用于特性检测。未来它可能会包含其他信息。

js
if (document.fragmentDirective) {
  log("Your browser supports text fragments.");
} else {
  log("Text fragments are not supported in your browser.");
}

规范

规范
URL Fragment Text Directives
# fragmentdirective

浏览器兼容性

另见