我想要做的是在使用 jQuery 的站点中启用后退和前进按钮。我现在有一个工作代码,但我很确定它太复杂了,我需要一些帮助来使它更容易并添加一个函数来让它继续前进。这是代码:
var recenturl;
var currenturl;
setInterval(function(){
currenturl = /[^/]*$/.exec(window.location.pathname)[0];
if(currenturl == 'menu_item1' || currenturl == 'menu_item2' || currenturl == 'menu_item3' || currenturl == 'menu_item4'){
if(currenturl != recenturl && recenturl != ''){
console.log(currenturl+" "+recenturl);
showFrame(currenturl);
if (typeof(window.history.pushState) == "function"){
window.history.pushState(null, currenturl, currenturl);
}
window.history.back();
recenturl = currenturl;
}
}
}, 100);
var xurl = /[^/]*$/.exec(window.location.pathname)[0];
if(xurl =='menu_item1' || xurl == 'menu_item2' || xurl == 'menu_item3' || xurl == 'menu_item4'){
showFrame(xurl);
if (typeof(window.history.pushState) == "function"){
window.history.pushState(null, xurl, xurl);
}
else {
window.location.hash = "#!" + xurl;
}
}
else {
if (xurl != " "){
var defaulturl = "/";
showFrame(defaulturl);
if (typeof(window.history.pushState) == "function"){
window.history.pushState(null, defaulturl, defaulturl);
}
else {
window.location.hash = "#!" + defaulturl;
}
}
}