| title | CustomEvent |
|---|---|
| slug | Web/API/CustomEvent |
| page-type | web-api-interface |
| browser-compat | api.CustomEvent |
{{APIRef("DOM")}}{{AvailableInWorkers}}
The CustomEvent interface can be used to attach custom data to an event generated by an application.
As an alternative to CustomEvent, you can subclass the Event interface to add custom data and behavior.
Note
If used to attempt to communicate between a web extension content script and a web page script, a non-string detail property throws with "Permission denied to access property" in Firefox. To avoid this issue clone the object. See Share objects with page scripts for more information.
{{InheritanceDiagram}}
- {{domxref("CustomEvent.CustomEvent", "CustomEvent()")}}
- : Creates a new
CustomEvent.
- : Creates a new
This interface inherits properties from its parent, {{domxref("Event")}}.
- {{domxref("CustomEvent.detail")}} {{ReadOnlyInline}}
- : Returns any data passed when initializing the event.
This interface inherits methods from its parent, {{domxref("Event")}}.
- {{domxref("CustomEvent.initCustomEvent()")}} {{deprecated_inline}}
- : Initializes a
CustomEventobject. If the event has already been dispatched, this method does nothing.
- : Initializes a
{{Specifications}}
{{Compat}}
- {{domxref("Window.postMessage()")}}
- Creating and dispatching events