0
setInterval(function(){
  if(current_url == ''){
    window.location.hash = '#!/home';
    current_url = window.location.hash.href;
  }
  else if(current_url !== window.location){
    change_page(window.location.hash.split('#!/')[1]);
    current_url = window.location.hash.href;
  }
},100)

我的 JavaScript / jQuery 的这一部分使 Mac 上的 Firefox 看起来只是在不断地重新加载。在 W7 上的 Firefox 上它没有,而在两个操作系统上的 Chrome 上它也可以正常工作。我怎样才能让它看起来不再像在 Firefox 上的超棒栏中加载一样?

仅供参考,我这样做是为了后退/前进按钮功能有效......

4

1 回答 1

2

尝试这个:

var hashChanged = function() {
  if(current_url == '') {
    window.location.hash = '#!/home';
    current_url = window.location.hash;
  }
  else if(current_url !== window.location.hash){
    change_page(window.location.hash.split('#!/')[1]);
    current_url = window.location.hash;
  }
};

if('onhashchange' in window) {
    window.onhashchange = hashChanged;
} else {
    setInterval(hashChanged, 100);
}
于 2010-11-18T19:15:46.900 回答