Repository navigation
Expand file tree
/
Copy pathindex.md
More file actions
48 lines (33 loc) · 1.49 KB
/
Copy pathindex.md
File metadata and controls
48 lines (33 loc) · 1.49 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
---
title: "HashChangeEvent: HashChangeEvent() constructor"
short-title: HashChangeEvent()
slug: Web/API/HashChangeEvent/HashChangeEvent
page-type: web-api-constructor
browser-compat: api.HashChangeEvent.HashChangeEvent
---
{{APIRef("HTML DOM")}}
The **`HashChangeEvent()`** constructor creates a new {{domxref("HashChangeEvent")}} object, that is used by the {{domxref("Window/hashchange_event", "hashchange")}} event fired at the {{domxref("window")}} object when the fragment of the URL changes.
> [!NOTE]
> A web developer doesn't typically need to call this constructor, as the browser creates these objects itself when firing {{domxref("Window/hashchange_event", "hashchange")}} events.
## Syntax
```js-nolint
new HashChangeEvent(type, options)
```
### Parameters
- `type`
- : A string with the name of the event.
It is case-sensitive and browsers set it to `hashchange`.
- `options` {{optional_inline}}
- : An object that, _in addition to the properties defined in {{domxref("Event/Event", "Event()")}}_, has the following properties:
- `oldURL` {{optional_inline}}
- : A string containing the old URL. Its default value is the empty string (`""`).
- `newURL` {{optional_inline}}
- : A string containing the new URL. Its default value is the empty string (`""`).
### Return value
A new {{domxref("HashChangeEvent")}} object.
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{domxref("Window/hashchange_event", "hashchange")}} event