getSupportedConstraints () 方法在 MediaDevices interface returns an object based on the MediaTrackSupportedConstraints dictionary, whose member fields each specify one of the constrainable properties the 用户代理 understands.

句法

var supportedConstraints = navigator.mediaDevices.getSupportedConstraints();
					

参数

None.

返回值

A new object based on the MediaTrackSupportedConstraints dictionary listing the constraints supported by the user agent. Because only constraints supported by the user agent are included in the list, each of these Boolean properties has the value true .

范例

This example outputs a list of the constraints supported by your browser.

HTML

<p>The following media constraints are supported by your browser:</p>
<ul id="constraintList">
</ul>
					

CSS

body {
  font: 15px Arial, sans-serif;
}
					

JavaScript

let constraintList = document.getElementById("constraintList");
let supportedConstraints = navigator.mediaDevices.getSupportedConstraints();
for (let constraint in supportedConstraints) {
  if (supportedConstraints.hasOwnProperty(constraint)) {
    let elem = document.createElement("li");
    elem.innerHTML = "<code>" + constraint + "</code>";
    constraintList.appendChild(elem);
  }
}
					

结果

规范

规范 状态 注释
媒体捕获和流
The definition of 'getSupportedConstraints()' in that specification.
候选推荐 初始定义。

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
getSupportedConstraints Chrome 53 Edge 12 Firefox 44 IE No Opera 40 Safari 11 WebView Android 53 Chrome Android 52 Firefox Android 50 Opera Android 41 Safari iOS 11 Samsung Internet Android 6.0

图例

完整支持

完整支持

不支持

不支持

元数据

  • 最后修改: