-
Notifications
You must be signed in to change notification settings - Fork 22.4k
/
index.md
60 lines (41 loc) · 1.33 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
60
---
title: PageTransitionEvent
slug: Web/API/PageTransitionEvent
page-type: web-api-interface
browser-compat: api.PageTransitionEvent
---
{{APIRef("HTML DOM")}}
The **`PageTransitionEvent`** event object is available inside handler functions for the [`pageshow`](/en-US/docs/Web/API/Window/pageshow_event) and [`pagehide`](/en-US/docs/Web/API/Window/pagehide_event) events, fired when a document is being loaded or unloaded.
{{InheritanceDiagram}}
## Constructor
- {{domxref("PageTransitionEvent.PageTransitionEvent", "PageTransitionEvent()")}}
- : Creates a new `PageTransitionEvent` object.
## Instance properties
_This interface also inherits properties from its parent, {{domxref("Event")}}._
- {{domxref("PageTransitionEvent.persisted")}} {{ReadOnlyInline}}
- : Indicates if the document is loading from a cache.
## Example
### HTML
```html
<!doctype html>
<html lang="en-US">
<body></body>
</html>
```
### JavaScript
```js
window.addEventListener("pageshow", (event) => {
if (event.persisted) {
alert("The page was cached by the browser");
} else {
alert("The page was NOT cached by the browser");
}
});
```
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [`pageshow`](/en-US/docs/Web/API/Window/pageshow_event) event
- [`pagehide`](/en-US/docs/Web/API/Window/pagehide_event) event