Navigator:xr 属性

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

安全上下文: 此项功能仅在一些支持的浏览器安全上下文(HTTPS)中可用。

实验性: 这是一项实验性技术
在将其用于生产之前,请仔细检查浏览器兼容性表格

Navigator 接口的 xr 只读属性返回一个 XRSystem 对象,该对象可用于访问 WebXR 设备 API

XRSystem 对象用于在当前上下文中与 WebXR 设备 API 进行交互。这可用于向用户呈现增强现实或者虚拟现实图像。

示例

每个 Window 对象都有自己的 Navigator 实例,可以通过 window.navigatornavigator 访问。同时,还会创建一个新的 XRSystem 实例,并将其作为 navigator.xr 附加到 navigator 实例上。如果存在 xr 属性,你可以使用它来访问 WebXR 设备 API

你可以使用以下代码判断 WebXR 是否可用:

js
if ("xr" in window.navigator) {
  /* WebXR 可用!*/
} else {
  /* 不支持 WebXR */
}

规范

Specification
WebXR Device API
# navigator-xr-attribute

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
xr
Experimental

Legend

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

Full support
Full support
No support
No support
Experimental. Expect behavior to change in the future.
See implementation notes.

参见