Event:isTrusted 属性

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

Event 接口的 isTrusted 只读属性是一个表示事件是否由用户行为生成的布尔值。当事件由用户行为触发时,为 true;当事件由脚本创建或修改,或通过 EventTarget.dispatchEvent() 派发时,为 false

一个布尔值。

示例

js
if (e.isTrusted) {
  /* 事件可信 */
} else {
  /* 事件不可信 */
}

规范

Specification
DOM
# ref-for-dom-event-istrusted①

浏览器兼容性

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
isTrusted

Legend

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

Full support
Full support
See implementation notes.