只读 xr property provided by the Navigator or WorkerNavigator interface returns an XR object which can be used to access the WebXR 设备 API .

句法

const xr = navigator.xr
					

XR object used to interface with the WebXR 设备 API in the current context. This can be used to present augmented and/or virtual reality imagery to the user.

用法注意事项

每个 Window has its own instance of Navigator , which can be accessed as Window.navigator or simply as navigator . At the same time, a new XR instance is also created and attached to the navigator instance as navigator.xr 。若 xr property exists and is non- null , you can use it to access the WebXR 设备 API .

To determine if WebXR is available, you can do something like this:

if ("xr" in Window.navigator) {
  /* WebXR can be used! */
} else {
  /* WebXR isn't available */
}
					

规范

规范 状态 注释
WebXR 设备 API
The definition of 'Navigator.xr' 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
xr Chrome 79 Edge 79 Firefox No IE No Opera No Safari No WebView Android No Chrome Android 79 Firefox Android No Opera Android No Safari iOS No Samsung Internet Android 11.2

图例

完整支持

完整支持

不支持

不支持

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

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

另请参阅

元数据

  • 最后修改: