代码之家  ›  专栏  ›  技术社区  ›  Oscar Godson

使用Firefox中的jQuery在“AJAX”url中不断加载

  •  0
  • Oscar Godson  · 技术社区  · 16 年前
    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和两个OSs上的Chrome都没有问题。我怎样才能让它看起来不再像是装在火狐的棒吧里?

    仅供参考,我这么做后退/前进按钮功能工作。。。

    1 回复  |  直到 16 年前
        1
  •  2
  •   Jacob Relkin    16 年前

    试试这个:

    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);
    }