当一条会话历史记录被执行的时候将会触发页面显示(pageshow)事件。(这包括了后退/前进按钮操作,同时也会在onload 事件触发后初始化页面时触发)
基本信息
- 规范
- HTML5
- 接口
- PageTransitionEvent
- 事件冒泡
- No
- 事件取消
- No
- 事件源
- Document (dispatched on Window)
- 默认操作
- None
属性
Property | Type | Description |
---|---|---|
target 只读 |
EventTarget |
The event target (the topmost target in the DOM tree). |
type 只读 |
DOMString |
The type of event. |
bubbles 只读 |
Boolean |
Whether the event normally bubbles or not. |
cancelable 只读 |
Boolean |
Whether the event is cancellable or not. |
persisted 只读 |
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()">
浏览器兼容性
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 | 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 |