我遇到了'popstate'事件处理程序的问题,这是我的代码:
window.addEventListener("popstate", function (event){
if (event.state) {
alert('abc')
}
});
// The data object is arbitrary and is passed with the popstate event.
var dataObject = {
createdAt: '2011-10-10',
author: 'donnamoss'
};
var url = '/posts/new-url';
history.pushState(dataObject, document.title, url);
Run Code Online (Sandbox Code Playgroud)
我预计这个代码会在执行时弹出一个警告框,但没有任何反应.
这里有什么不对吗?
谢谢.
ota*_*tay 19
pushState不要触发popstate事件,只需单击后退/前进按钮(或使用退格键)或调用history.back()/ history.go(n)将触发此事件.
此外,在webkit浏览器中,popstate事件将在页面onload事件之后触发,但Firefox和IE不具有此行为.
| 归档时间: |
|
| 查看次数: |
12077 次 |
| 最近记录: |