--- title: pageshow slug: Web/API/Window/pageshow_event translation_of: Web/API/Window/pageshow_event original_slug: Web/Events/pageshow ---
当一条会话历史记录被执行的时候将会触发页面显示(pageshow)事件。(这包括了后退/前进按钮操作,同时也会在onload 事件触发后初始化页面时触发)
Property | Type | Description |
---|---|---|
target {{readonlyInline}} |
{{domxref("EventTarget")}} | The event target (the topmost target in the DOM tree). |
type {{readonlyInline}} |
{{domxref("DOMString")}} | The type of event. |
bubbles {{readonlyInline}} |
{{jsxref("Boolean")}} | Whether the event normally bubbles or not. |
cancelable {{readonlyInline}} |
{{jsxref("Boolean")}} | Whether the event is cancellable or not. |
persisted {{readonlyInline}} |
{{jsxref("boolean")}} | 表示网页是否是来自缓存. |
以下示例将会在控制台打印由前进/后退按钮以及load事件触发后引起的pageshow事件:
window.addEventListener('pageshow', function(event) { console.log('after , pageshow :',event); }); window.addEventListener('load', function() { console.log('before'); });
不规范的写法,你同样可以将这个事件当做一个属性添加到body标签,类似于onload
<body onload="myonload()" onpageshow="mypageshowcode()">
{{CompatibilityTable()}}
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | {{CompatChrome("4")}} | {{CompatGeckoDesktop("1.8")}} | 11 | 15 | 5 |
Feature | Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
Basic support | 2.3 | {{CompatUnknown()}} | 11 | 35 | 5.1 |