We're looking for a user researcher to understand the needs of developers and designers. Is this you or someone you know? Check out the post: https://mzl.la/2IGzdXS

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

We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help!

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

Document Tags and Contributors

Last updated by: fscholz,