此頁面由社群從英文翻譯而來。了解更多並加入 MDN Web Docs 社群。

View in English Always switch to English

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 ⁨2016年9月⁩.

備註: 此功能可在 Web Worker 中使用。

Event 介面的 isTrusted 唯讀屬性是一個布林值,當事件是由使用者代理(包含透過使用者行為與程式方法,例如 HTMLElement.focus())產生時為 true,而當事件是透過 EventTarget.dispatchEvent() 發送時則為 false。唯一的例外是 click 事件,其在使用者代理中會將 isTrusted 屬性初始化為 false

一個布林值。

範例

js
if (e.isTrusted) {
  /* 事件是受信任的 */
} else {
  /* 事件不受信任 */
}

規範

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

瀏覽器相容性