Onpageshow event
More examples are included at the bottom of this article.
Definitions and usages
The onpageshow event is triggered when a user browses the web.
The onpageshow event is similar to the onload event, which is triggered the first time the page is loaded, and the onpageshow event is triggered each time the page is loaded, i.e. the onload event is not triggered when the page is read from the browser cache.
To see 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. If the page reads the property from the browser's cache to return the ture, otherwise false (see "more instances" below).
Browser support
The numbers in the table support the version number of the first browser for the event.
Event | |||||
---|---|---|---|---|---|
onpageshow | Yes | 11.0 | Yes | 5.0 | Yes |
Grammar
In HTML:
In JavaScript:
In JavaScript, use the addEventListener() method:
Note: Browsers with Internet Explorer8 and earlier versions of IE do not support the addEventListener() method.
Technical details
Whether to support bubbling: | No |
---|---|
Can I cancel: | No |
Types of events: | PageTransitionEvent |
Supported HTML tags: | <body> |
More instances
See if the page is read from the browser cache:
alert ("Does the page read from the browser cache? " . . . event.persisted);
}
Try it out . . .
The event object