gpt4 book ai didi

javascript - 检测浏览器对滚动到文本片段的支持(:~:text=) feature?

转载 作者:行者123 更新时间:2023-12-05 03:51:26 25 4
gpt4 key购买 nike

Google 最近开始在其突出显示的代码段中推出 Scroll-To-Text Frament 功能。这样做会将 #:~:text=... 参数附加到链接的 url,浏览器使用该参数突出显示目标网站上的代码段文本。

至于现在(2020 年 7 月),滚动到文本片段是一个 W3C Community Group Draft Reportbrowser support is very limited (截至目前基本上是基于 Chromium 的浏览器)。

我的问题是:有什么方法可以检测浏览器是否支持此功能? IE。使用 javascript?

最佳答案

From the spec :

3.7. Feature Detectability

For feature detectability, we propose adding a new FragmentDirectiveinterface that is exposed via document.fragmentDirective if theUA supports the feature.

[Exposed=Window]
interface FragmentDirective {};

We amend the Document interface to include a fragmentDirectiveproperty:

partial interface Document {
[SameObject] readonly attribute FragmentDirective fragmentDirective;
};

所以你可以使用

const isAvailable = "fragmentDirective" in window.document;

const isAvailable = !!window.FragmentDirective;

关于javascript - 检测浏览器对滚动到文本片段的支持(:~:text=) feature?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62874072/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com