安全上下文
此特征只可用于 安全上下文 (HTTPS),在某些或所有 支持浏览器 .

The WebXR Device API's XRSessionEvent() constructor creates and returns a new XRSessionEvent 对象。 These objects represent events announcing state changes in an XRSession representing an augmented or virtual reality session.

句法

newXRSessionEvent = new XRSessionEvent(type, eventInitDict);
					

参数

type
DOMString indicating which of the events represented by objects of type XRSessionEvent this particular object represents. See 事件类型 for a list of the permitted values.
eventInitDict

An object conforming to the XRSessionEventInit dictionary which contains values to be applied to the newly-created event object. Permitted values are:

session
XRSession to which the event is to be delivered.

返回值

A newly-created XRSessionEvent object representing an object of the specfied type and configured as described by the eventInitDict 参数。

事件类型

The following events are represented using the XRSessionEvent interface, and are permitted values for its type 特性。

end
Fired at the session when it has ended, after being terminated by the application or the 用户代理 .
visibilitychange

Fired at the session whenever its visibility state changes.

范例

This example creates a listiener that watches for the visibility state of the session to change. It reacts by calling a function mySessionVisible() with a Boolean indicating whether or not the session is visible; this function might, for instance, spin up or reconfigure a worker that handles rendering the scene.

xrSession.addEventListener("visibilitystate", e => {
  switch(e.session.visibilitystate) {
    case "visible":
    case "visible-blurred":
      mySessionVisible(true);
      break;
    case "hidden":
      mySessionVisible(false);
      break;
  }
});
					

规范

规范 状态 注释
WebXR 设备 API
The definition of 'XRSessionEvent() constructor' 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
XRSessionEvent() 构造函数 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

图例

完整支持

完整支持

不支持

不支持

元数据

  • 最后修改: