CustomEvent
interface represents events initialized by an application for any purpose.
CustomEvent()
CustomEvent
.
CustomEvent.detail
只读
Any data passed when initializing the event.
This interface inherits properties from its parent,
事件
:
Event.bubbles
只读
布尔指示事件是否透过 DOM 冒泡。
Event.cancelBubble
Event.stopPropagation()
。把其值设为
true
在从事件处理程序返回之前阻止事件的传播。
Event.cancelable
只读
布尔指示事件是否可取消。
Event.composed
只读
A boolean indicating whether or not the event can bubble across the boundary between the shadow DOM and the regular DOM.
Event.currentTarget
只读
Event.deepPath
数组
of DOM
节点
s through which the event has bubbled.
Event.defaultPrevented
只读
event.preventDefault()
canceled the event.
Event.eventPhase
只读
Indicates which phase of the event flow is being processed.
Event.explicitOriginalTarget
只读
The explicit original target of the event (Mozilla-specific.)
Event.originalTarget
只读
The original target of the event, before any retargetings. (Mozilla-specific.)
Event.returnValue
Event.preventDefault()
and
Event.defaultPrevented
instead, but you can use
returnValue
if you choose to do so.
Event.srcElement
Event.target
. Some other browsers are starting to support it for web compatibility purposes.
Event.target
只读
A reference to the target to which the event was originally dispatched.
Event.timeStamp
只读
DOMHighResTimeStamp
代替。
Event.type
只读
The name of the event. Case-insensitive.
Event.isTrusted
只读
Event.initEvent
).
Event.scoped
只读
composed
instead. (A
布尔
indicating whether the given event will bubble across through the shadow root into the standard DOM.)
CustomEvent.initCustomEvent()
初始化
CustomEvent
object. If the event has already being dispatched, this method does nothing.
This interface inherits methods from its parent,
事件
:
Event.createEvent()
创建新事件,然后必须被初始化通过调用其
initEvent()
方法。
Event.composedPath()
ShadowRoot.mode
closed.
Event.initEvent()
初始化创建事件的值。若事件已被分派,此方法什么都不做。
Event.preventDefault()
取消事件 (若它可取消)。
Event.stopImmediatePropagation()
For this particular event, prevent all other listeners from being called. This includes listeners attached to the same element as well as those attached to elements that will be traversed later (during the capture phase, for instance).
Event.stopPropagation()
停止在 DOM 中进一步传播事件。
Event.getPreventDefault()
Event.defaultPrevented
instead. (Returns the value of
Event.defaultPrevented
)。
Event.preventBubble()
从 Gecko 24 起已过时
event.stopPropagation
instead. (Prevents the event from bubbling.)
Event.preventCapture()
从 Gecko 24 起已过时
event.stopPropagation
代替。
| 规范 | 状态 | 注释 |
|---|---|---|
|
DOM
The definition of 'CustomEvent' in that specification. |
实时标准 | 初始定义。 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
CustomEvent
|
Chrome 15 | Edge 12 | Firefox 6 | IE 9 | Opera 11 | Safari 5.1 | WebView Android ≤37 | Chrome Android 18 | Firefox Android 6 | Opera Android 11 | Safari iOS 6 | Samsung Internet Android 1.0 |
CustomEvent()
构造函数
|
Chrome 15 | Edge ≤18 | Firefox 11 | IE No | Opera 11.6 | Safari 6.1 | WebView Android ≤37 | Chrome Android 18 | Firefox Android 14 | Opera Android 12 | Safari iOS 6.1 | Samsung Internet Android 1.0 |
detail
|
Chrome 15 | Edge 14 | Firefox 11 | IE No | Opera 11.6 | Safari 6.1 | WebView Android Yes | Chrome Android Yes | Firefox Android 14 | Opera Android Yes | Safari iOS 6.1 | Samsung Internet Android Yes |
initCustomEvent
弃用
|
Chrome
Yes
|
Edge 14 | Firefox 6 | IE 9 | Opera 11 | Safari 5.1 |
WebView Android
Yes
|
Chrome Android
Yes
|
Firefox Android 6 | Opera Android Yes | Safari iOS Yes |
Samsung Internet Android
Yes
|
| Available in workers | Chrome Yes | Edge 12 | Firefox 48 | IE Yes | Opera Yes | Safari Yes | WebView Android Yes | Chrome Android Yes | Firefox Android 48 | Opera Android Yes | Safari iOS Yes | Samsung Internet Android Yes |
完整支持
不支持
弃用。不要用于新网站。
见实现注意事项。
When firing a
CustomEvent
from privileged code (i.e. an extension) to non-privileged code (i.e. a webpage), security issues should be considered. Firefox and other Gecko applications restrict an object created in one context from being directly used for another, which will automatically prevent security holes, but these restrictions may also prevent your code from running as expected.
While creating a
CustomEvent
object, you must create the object from the same
window
。
detail
attribute of your
CustomEvent
will be subjected to the same restrictions.
字符串
and
数组
values will be readable by the content without restrictions, but custom
对象
will not. While using a custom object, you will need to define the attributes of that object that are readable from the content script using
Components.utils.cloneInto()
.
// doc is a reference to the content document
function dispatchCustomEvent(doc) {
var eventDetail = Components.utils.cloneInto({foo: 'bar'}, doc.defaultView);
var myEvent = doc.defaultView.CustomEvent("mytype", eventDetail);
doc.dispatchEvent(myEvent);
}
But one needs to keep in mind that exposing a function will allow the content script to run it with chrome privileges, which can open a security vulnerability.
CustomEvent
AbortController
AbortSignal
AbstractRange
Attr
ByteString
CDATASection
CSSPrimitiveValue
CSSValue
CSSValueList
CharacterData
ChildNode
注释
DOMConfiguration
DOMError
DOMErrorHandler
DOMException
DOMImplementation
DOMImplementationList
DOMImplementationRegistry
DOMImplementationSource
DOMLocator
DOMObject
DOMParser
DOMPoint
DOMPointInit
DOMPointReadOnly
DOMRect
DOMString
DOMTimeStamp
DOMTokenList
DOMUserData
Document
DocumentFragment
DocumentType
元素
ElementTraversal
Entity
EntityReference
事件
EventTarget
HTMLCollection
MutationObserver
节点
NodeFilter
NodeIterator
NodeList
NonDocumentTypeChildNode
ProcessingInstruction
PromiseResolver
范围
StaticRange
文本
TextDecoder
TextEncoder
TimeRanges
TreeWalker
TypeInfo
USVString
UserDataHandler
XMLDocument