2

有什么方法可以检测(不使用user-agent和类似的).focus()支持focusOptions的方法,例如:preventScroll: true

我在 Chrome 中使用它:

element.focus({
  preventScroll: true
});

当然,这在 Chrome 和 Opera 之外的任何地方都行不通。但是我怎么能检测到呢?喜欢:

try { window.focus().preventScroll } catch {...}

有可能吗?

4

1 回答 1

1

你可以试试这个:

    let supported = false;

    document.createElement('div').focus({
        get preventScroll() {
            supported = true;

            return false;
        },
    });

    console.log(supported);
于 2019-12-29T10:42:15.740 回答