onpageshow
Event
Example
Triggers JavaScript when the user navigates to the webpage:
More examples are included at the bottom of this article.
Definition and Usage
The onpageshow event is triggered when the user navigates to the webpage.
The onpageshow event is similar to the onload event, which is triggered when the page is first loaded. The onpageshow event is triggered every time the page is loaded, whereas the onload event is not triggered when the page is read from the browser cache.
To determine whether the page is loaded directly from the server or from the cache, you can use the persisted property of the PageTransitionEvent object. This property returns true if the page is read from the browser cache, and false otherwise (see "More Examples" below).
Browser Support
The numbers in the table specify the first browser version that fully supports the event.
Event | |||||
---|---|---|---|---|---|
onpageshow | Yes | 11.0 | Yes | 5.0 | Yes |
Syntax
In HTML:
In JavaScript:
In JavaScript, using the addEventListener() method:
Note: The addEventListener() method is not supported in Internet Explorer 8 and earlier versions.
Bubbles: | No |
---|---|
Cancelable: | No |
--- | --- |
Event Type: | PageTransitionEvent |
--- | --- |
Supported HTML Tags: | <body> |
--- | --- |
More Examples
Example
Check if the page is read from the browser cache: