PushState 不是对哈希的操作。如果你希望它
PushState 正在更改 url 而不更改页面:
如果你把历史看作一个数组,history = [];
您打开浏览器的空首页并转到 page1.html
现在历史是=['page1.html']
.
如果您使用 URL page2.html 从 page1.html 触发 PushState,那么历史记录现在是['page1.html','page2.html']
地址栏显示page2.html。
如果浏览器不支持pushState,它什么也不做。所以对于你的例子:
$("#close").live("click", function(event) {
$("#board").slideUp("slow");
window.history.pushState(null, null, site_url+"/");
return false;
});
当你加载ajax时:
window.history.pushState(null,null,site_url + "/" + ajax_url);
如果你想使用哈希进行操作,你可以这样做:
$("#close").live("click", function(event) {
$("#board").slideUp("slow");
window.location.href = "#/"
return false;
});
当你加载ajax时:
window.location.href = "#/" + ajax_url
如果您使用 PushState,请注意 url 可能会结束指向您没有的子文件夹中的操作,因此您需要某种 .htaccess 重写代码