Event.isTrusted

Event 接口的 isTrusted 属性是一个只读属性,它是一个布尔值(Boolean)。当事件是由用户行为生成的时候,这个属性的值为 true ,而当事件是由脚本创建、修改、通过 EventTarget.dispatchEvent() 派发的时候,这个属性的值为 false 。

语法

var eventIsTrusted = event.isTrusted;

Boolean (布尔值)

示例

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

规范

规范 现状 意见
DOM
Event.isTrusted
Living Standard
Document Object Model (DOM) Level 3 Events Specification
Trusted events
Obsolete 添加有关受信任与不受信任事件的请求,而 isTrusted 属性并非由其定义。

浏览器支持

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
isTrustedChrome Full support 46
Notes
Full support 46
Notes
Notes Starting with Chrome 53 and Opera 40, untrusted events do not invoke the default action.
Edge Full support 12Firefox Full support YesIE No support No
Notes
No support No
Notes
Notes In Internet Explorer, all events are trusted except those that are created with the createEvent() method.
Opera Full support 33
Notes
Full support 33
Notes
Notes Starting with Chrome 53 and Opera 40, untrusted events do not invoke the default action.
Safari Full support 10WebView Android Full support 46
Notes
Full support 46
Notes
Notes Starting with version 53, untrusted events do not invoke the default action.
Chrome Android Full support 46
Notes
Full support 46
Notes
Notes Starting with Chrome 53 and Opera 40, untrusted events do not invoke the default action.
Firefox Android Full support YesOpera Android Full support 33
Notes
Full support 33
Notes
Notes Starting with Chrome 53 and Opera 40, untrusted events do not invoke the default action.
Safari iOS Full support 10Samsung Internet Android Full support 5.0
Notes
Full support 5.0
Notes
Notes Starting with Samsung Internet 6.0 and Opera 40, untrusted events do not invoke the default action.

Legend

Full support  
Full support
No support  
No support
See implementation notes.
See implementation notes.