//原地址abc.com/sss.html //abc.com/sss.html#dsf window.location.hash = "dsf"; //abc.com/my/awesome/url var stateObject = {}; var title = "Wow Title"; var newUrl = "/my/awesome/url"; history.pushState(stateObject,title,newUrl);
监听 hash 值 即: # 后面的值变化
window.onhashchange = function(){
alert(window.location.hash);
};
** 重写 history.pushState方法
history.pushState = function(){
alert("sdf");
}
** 一个完整的 根据 hash 变化 执行 方法 的 实例
if(window.location.hash != ""){
window.location.hash = "";
}
window.onhashchange = function(){
if((window.location.hash).indexOf("show") > -1){
coverShow();
}else{
coverHide();
}
};
$('.top_bar .menu').tap(function(){
if((window.location.hash).indexOf("show") > -1){
window.location.hash = "";
}else{
window.location.hash = "show";
}
});
function coverShow(){
}
function coverHide(){
}