--- title: Event.isTrusted slug: Web/API/Event/isTrusted translation_of: Web/API/Event/isTrusted ---
{{APIRef("DOM")}}
{{domxref("Event")}} 介面的 isTrusted
唯讀屬性為一個布林值,若事件物件是由使用者操作而產生,則 isTrusted
值為 true
。若事件物件是由程式碼所建立、修改,或是透過 {{domxref("EventTarget.dispatchEvent()")}} 來觸發,則 isTrusted
值為 false
。
var bool = event.isTrusted;
if (e.isTrusted) { /* The event is trusted. */ } else { /* The event is not trusted. */ }
Specification | Status | Comment |
---|---|---|
{{SpecName('DOM WHATWG', '#dom-event-istrusted', 'Event.isTrusted')}} | {{ Spec2('DOM WHATWG') }} | |
{{SpecName('DOM3 Events', '#trusted-events', 'Trusted events')}} | {{Spec2('DOM3 Events')}} | Adds requirements regarding trusted and untrusted events, though it does not itself define the isTrusted property. |
{{SpecName('DOM4', '#dom-event-istrusted', 'Event.isTrusted')}} | {{Spec2('DOM4')}} | Initial definition. |
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|
Basic support | {{CompatChrome(46.0)}} | {{CompatVersionUnknown}} | {{CompatNo}} [1] | {{CompatOpera(33)}} | {{CompatNo}} |
Feature | Android | Android Webview | Firefox Mobile (Gecko) | Firefox OS | IE Mobile | Opera Mobile | Safari Mobile | Chrome for Android |
---|---|---|---|---|---|---|---|---|
Basic support | {{CompatUnknown}} | {{CompatChrome(46.0)}} | {{CompatVersionUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatOperaMobile(33)}} | {{CompatNo}} | {{CompatChrome(46.0)}} |
[1] In Internet Explorer, all events are trusted except those that are created with the createEvent()
method.