Navigator:userActivation 属性

Baseline 2023
Newly available

Since November 2023, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.

Navigator 接口的 userActivation 只读属性返回一个 UserActivation 对象,该对象包含有关当前窗口用户激活状态的信息。

一个 UserActivation 对象。

示例

检查最近是否执行了用户手势

使用 UserActivation.isActive 来检查用户是否正在与页面进行交互(短暂激活)。

js
if (navigator.userActivation.isActive) {
  // 例如,继续请求播放媒体
}

检查是否曾执行过用户手势

使用 UserActivation.hasBeenActive 检查用户是否曾经与页面进行过交互(粘性激活)。

js
if (navigator.userActivation.hasBeenActive) {
  // 例如,继续自动播放动画
}

规范

Specification
HTML
# dom-navigator-useractivation

浏览器兼容性

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
userActivation

Legend

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

Full support
Full support
No support
No support

参见