DOMTokenList.supports()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

如果给定的 token 位于关联属性支持的 token 列表中,则 DOMTokenList 接口的 supports() 方法返回 true。这个方法旨在支持特性检查。

语法

js
supports(token);

参数

token

一个字符串,包含了用于查询的 token。

返回值

一个布尔值,表示是否查询到 token。

示例

js
const iframe = document.getElementById("display");

if (iframe.sandbox.supports("an-upcoming-feature")) {
  // support code for mystery future feature
} else {
  // fallback code
}

if (iframe.sandbox.supports("allow-scripts")) {
  // instruct frame to run JavaScript
  //
  // (NOTE: This feature is well-supported; this is just an example!)
  //
}

规范

Specification
DOM
# ref-for-dom-domtokenlist-supports①

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
supports

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support