Navigator:xr 属性
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Navigator
接口的 xr
只读属性返回一个 XRSystem
对象,该对象可用于访问 WebXR 设备 API。
值
XRSystem
对象用于在当前上下文中与 WebXR 设备 API 进行交互。这可用于向用户呈现增强现实或者虚拟现实图像。
示例
每个 Window
对象都有自己的 Navigator
实例,可以通过 window.navigator
或 navigator
访问。同时,还会创建一个新的 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 GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
xr |
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.
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.
参见
- WebGL API:用于 Web 的 2D 和 3D 加速图形
- Canvas API:2D 图形 API