过时
This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it.

getVRDisplays() 方法在 Navigator interface returns a promise that resolves to an array of VRDisplay objects representing any available VR displays connected to the computer.

句法

navigator.getVRDisplays().then(function(displays) {
  // Do something with the available VR displays
});
					

参数

None.

返回值

A promise that resolves to an array of VRDisplay 对象。

范例

if(navigator.getVRDisplays) {
  console.log('WebVR 1.1 supported');
  // Then get the displays attached to the computer
  navigator.getVRDisplays().then(function(displays) {
    // If a display is available, use it to present the scene
    if(displays.length > 0) {
      vrDisplay = displays[0];
      // Now we have our VRDisplay object and can do what we want with it
    }
  });
}
					

注意 : You can see this complete code at raw-webgl-example .

规范

规范 状态 注释
WebVR 1.1
The definition of 'getVRDisplays()' in that specification.
草案 初始定义

浏览器兼容性

更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
getVRDisplays 弃用 Chrome No
不支持 No
Available on all platforms behind a flag, but currently only works on desktop in an experimental version of Chrome (other builds won't return any devices when Navigator.getVRDisplays() is invoked).
Edge 15 — 79 Firefox 55
55
Windows support was enabled in Firefox 55.
64
macOS support was enabled in Firefox 64.
IE No Opera No Safari No WebView Android ? — 80 Chrome Android ? — 80
不支持 ? — 80
Currently supported only by Google Daydream.
Firefox Android 55 Opera Android No Safari iOS No Samsung Internet Android No

图例

完整支持

完整支持

不支持

不支持

实验。期望将来行为有所改变。

实验。期望将来行为有所改变。

弃用。不要用于新网站。

弃用。不要用于新网站。

见实现注意事项。

另请参阅

元数据

  • 最后修改: