當我在Safari 5中觸發我的popState(頁面返回)時,我似乎無法訪問window.history.state對象。此代碼完美適用於Chrome 19和Firefox 12.pushState&popState:Safari 5沒有返回window.history.state
window.onload = function() {
window.setTimeout(function() {
var original = window.location.href;
window.addEventListener("popstate", function(e) {
if (window.history.state !== null) {
var type = window.history.state.type;
var page = window.history.state.page;
//custom Ajax function below
getContent({type:type, page:page, category: category}, '/' + type + '/' + page);
} else {
window.location = original;
}
}, false);
}, 1);
}
Safari 5中的console.log(window.history.state)返回'undefined'。
http://stackoverflow.com/questions/8439145/reading- window-history-state-object-in-webkit 這將用於你。 – Laughing