1
現在我正在使用window.location.hash進行如下歷史記錄管理,我如何用HTML5歷史推送狀態替換它。如何使用HTML5歷史推狀態而不是window.location.hash?
var stateHistory = [];
function changeHistory(page) {
var l = stateHistory.length,
state = window.location.hash;
if (l === 0) {
stateHistory.push(state);
return;
}
if (state === stateHistory[l - 2]) {
stateHistory.pop();
} else {
stateHistory.push(state);
}
};
你可以找到關於如何使用[MDN文檔】在歷史API的指南(https://developer.mozilla.org/ zh-CN/docs/Web/Guide/API/DOM/Manipulating_the_browser_history)和[various](http://diveintohtml5.info/history.html)[other](http://html5doctor.com/history-api/) [站點](https://www.google.com/search?q=html5+history+api)。你只需要*搜索它。 –