W3cubDocs

/DOM Events

pageshow

The pageshow event is fired when a session history entry is being traversed to. (This includes back/forward as well as initial page-showing after the onload event.)

General info

Specification
HTML5
Interface
PageTransitionEvent
Bubbles
No
Cancelable
No
Target
Document (dispatched on Window)
Default Action
None

Properties

Property Type Description
target Read only EventTarget The event target (the topmost target in the DOM tree).
type Read only DOMString The type of event.
bubbles Read only Boolean Whether the event normally bubbles or not.
cancelable Read only Boolean Whether the event is cancellable or not.
persisted Read only boolean Persisted user state.

Examples

The following will log info about the pageshow event, which is fired on back/forward, not just after onload:

window.addEventListener('pageshow', function(event) {
    console.log('pageshow:');
    console.log(event);
});

While not best-practice, you can also add the event as an attribute on the body tag, same as onload:

<body onload="myonload()" onpageshow="mypageshowcode()">

Browser compatibility

Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari
Basic support 4 (Yes) 1.5 (1.8) 11 15 5
Feature Android Edge Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support 2.3 (Yes) ? 11 35 5.1

© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/Events/pageshow