onpageshow event
Example
Trigger JavaScript when the user browses the web page:
Try it »
The bottom of this article contains more examples.
Definition and Usage
The onpageshow event is triggered when the user browses the web page.
The onpageshow event is similar to onload the event. The onload event is triggered the first time the page is loaded, while the onpageshow event is triggered every time the page is loaded, meaning 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. If the page is read from the browser cache, this property returns true; otherwise it returns false (see the "More examples" below).
Browser support
The numbers in the table indicate the version number of the first browser to support the event.
| Events | |||||
|---|---|---|---|---|---|
| onpageshow | Yes | 11.0 | Yes | 5.0 | Yes |
Syntax
In HTML:
<
element
onpageshow="
myScript
">Try it
In JavaScript:
object
.onpageshow=function(){
myScript
};
Try it
In JavaScript, use the addEventListener() method:
object
.addEventListener("pageshow",
myScript
);
Try it
Note: Internet Explorer 8 and earlier IE version browsers do not support addEventListener() method.
Technical Details
| Does it support bubbling: | No |
|---|---|
| Is it cancelable: | No |
| Event type: | PageTransitionEvent |
| Supported HTML tags: |
More examples
Example
Check whether the page is read from the browser cache:
function myFunction(event) {
alert("Is this page read from the browser cache? " + event.persisted);
}
Try it »
Event Object