-
Notifications
You must be signed in to change notification settings - Fork 22.4k
/
index.md
59 lines (38 loc) · 1.37 KB
/
index.md
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
50
51
52
53
54
55
56
57
58
59
---
title: HashChangeEvent
slug: Web/API/HashChangeEvent
page-type: web-api-interface
browser-compat: api.HashChangeEvent
---
{{APIRef("HTML DOM")}}
The **`HashChangeEvent`** interface represents events that fire when the fragment identifier of the URL has changed.
The fragment identifier is the part of the URL that follows (and includes) the `#` symbol.
{{InheritanceDiagram}}
## Constructor
- {{domxref("HashChangeEvent.HashChangeEvent", "HashChangeEvent()")}}
- : Creates a new `HashChangeEvent` object.
## Instance properties
_This interface also inherits the properties of its parent, {{domxref("Event")}}._
- {{domxref("HashChangeEvent.newURL")}} {{ReadOnlyInline}}
- : The new URL to which the window is navigating.
- {{domxref("HashChangeEvent.oldURL")}} {{ReadOnlyInline}}
- : The previous URL from which the window was navigated.
## Instance methods
_This interface has no methods of its own, but inherits the methods of its parent, {{domxref("Event")}}._
## Examples
### Basic example
```js
function locationHashChanged() {
if (location.hash === "#somecoolfeature") {
somecoolfeature();
}
}
window.addEventListener("hashchange", locationHashChanged);
```
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## Related events
- {{domxref("window.hashchange_event", "hashchange")}}
- {{domxref("window.popstate_event", "popstate")}}