onpageshowEvent
Examples
Trigger JavaScript when the user browses a page:
Try it Yourself »
More examples are included at the bottom of this article.
Definition and Usage
The onpageshow event is triggered when the user browses a page.
The onpageshow event is similar to theonloadonload event. The onload event is triggered when the page is loaded for the first time, while the onpageshow event is triggered every time the page is loaded. That is, the onload event is not triggered when the page is read from the browser cache.
To check whether the page is loaded directly from the server or read from the cache, you can use the persisted property of the PageTransitionEvent object to determine this. If the page is read from the browser cache, this property returns true, otherwise it returns false (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:Internet Explorer 8 and earlier IE versions do not support theaddEventListener()method.
Technical Details
| Bubbles: | No |
|---|---|
| Cancelable: | No |
| Event type: | PageTransitionEvent |
| Supported HTML tags: | <body> |

More Examples
Examples
Check whether the page is read from the browser cache:
alert("Was this page loaded from browser cache? " + event.persisted);
}
Try it Yourself »
Event Object Other Extensions