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 Does the event normally bubble?
cancelable Read only boolean Is it possible to cancel the event?
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()">

Compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support Yes (since 2009) 1.5+ IE11 ? ?
Feature Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support ? ? ? ? ?

 

Document Tags and Contributors

Contributors to this page: mnoorenberghe, Luke314, teoli, MattBrubeck, Sheppy, ethertank, louisremi
Last updated by: mnoorenberghe,