Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

我們的志工尚未將此文章翻譯為 正體中文 (繁體) 版本。加入我們,幫忙翻譯!

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 Firefox (Gecko) Internet Explorer Opera Safari
Basic support 4 1.5 (1.8) 11 15 5
Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support 2.3 ? 11 35 5.1

文件標籤與貢獻者

 最近更新: Haroenv,