We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
H5中扩展了history对象功能,使其具有更加丰富的能力,下面简单介绍一下!
location.hash
popstate
event.state
null
url
// 假设加入当前url为:http://www.c.com/ history.pushState(null, null, '?page=1'); // 此时当前url为:http://www.c.com/?page=1
pushState
// 假设加入当前url为:example.com/example.html history.pushState({page: 1}, 'title 1', '?page=1'); history.pushState({page: 2}, 'title 2', '?page=2'); history.replaceState({page: 3}, 'title 3', '?page=3'); // 此时example.com/example.html?page=2已经不存在了 history.back() // url显示为http://example.com/example.html?page=1 history.back() // url显示为http://example.com/example.html history.go(2) // url显示为http://example.com/example.html?page=3
state
history
replaceState
back
forward
go
window.addEventListener("hashchange", function () { console.log(1); }, false); location.hash = 'newhash';
The text was updated successfully, but these errors were encountered:
No branches or pull requests
H5中扩展了history对象功能,使其具有更加丰富的能力,下面简单介绍一下!
pushState
location.hash
类似popstate
事件触发时,该对象会传入回调函数,通过event.state
访问,如果不需要这个对象,此处可以填null
null
url
是否存在,即使不存在也不会报错。replaceState
pushState
方法一模一样history.state
state
对象,即上述方法的第一个参数popstate事件
history
对象)出现变化时,就会触发popstate
事件replaceState
或pushState
不会触发该事件,调用back
、forward
、go
或者点击浏览器的前进或后退时才会触发,有些浏览器在触发window.onload时也会触发popstate
hashchange事件
location.hash
的变化一图概括
参考
The text was updated successfully, but these errors were encountered: