UserActivation: hasBeenActive 属性

Baseline 2023
新推出

自 ⁨2023 年 11 月⁩ 起,此功能可在最新的设备和浏览器版本中运行。此功能可能不适用于较旧的设备或浏览器。

UserActivation 接口中只读的 hasBeenActive 属性指示当前窗口是否具有粘性用户激活

布尔值。

示例

检查是否执行过用户手势

使用 hasBeenActive 属性来检查自页面加载以来用户是否与页面进行过交互。

js
if (navigator.userActivation.hasBeenActive) {
  // proceed with auto-playing an animation, for example
}

规范

规范
HTML
# dom-useractivation-hasbeenactive

浏览器兼容性

另见