pageshow
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
当一条会话历史记录被执行的时候将会触发页面显示 (pageshow) 事件。(这包括了后退/前进按钮操作,同时也会在 onload 事件触发后初始化页面时触发)
基本信息
属性
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()">
规范
Specification |
---|
HTML Standard # event-pageshow |
浏览器兼容性
BCD tables only load in the browser