Repository navigation
Expand file tree
/
Copy pathindex.md
More file actions
49 lines (30 loc) · 1.67 KB
/
Copy pathindex.md
File metadata and controls
49 lines (30 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
---
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](/en-US/docs/Web/API/Document_Object_Model/Events#adding_custom_data_–_subclassing_event) 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](/en-US/docs/Mozilla/Add-ons/WebExtensions/Sharing_objects_with_page_scripts) for more information.
{{InheritanceDiagram}}
## Constructor
- {{domxref("CustomEvent.CustomEvent", "CustomEvent()")}}
- : Creates a new `CustomEvent`.
## Instance properties
_This interface inherits properties from its parent, {{domxref("Event")}}._
- {{domxref("CustomEvent.detail")}} {{ReadOnlyInline}}
- : Returns any data passed when initializing the event.
## Instance methods
_This interface inherits methods from its parent, {{domxref("Event")}}._
- {{domxref("CustomEvent.initCustomEvent()")}} {{deprecated_inline}}
- : Initializes a `CustomEvent` object. If the event has already been dispatched, this method does nothing.
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{domxref("Window.postMessage()")}}
- [Creating and dispatching events](/en-US/docs/Web/API/Document_Object_Model/Events#creating_and_dispatching_events)