2013-02-15 47 views
0

有什么方法可以检测jQuery中top.location.href或window.location.href的变化吗?尝试像通过jQuery检测top.location.href的变化

top.location.href.change(function() {}); 

已经,但它没有奏效。

有什么想法?

更新:我想防止帧打破框。该框架可能不会更改主页面的top.location.href。

谢谢! indect

+0

你到底抓到底是什么?通过历史记录API进行更改?你知道,顶部位置的大部分变化会使你的页面刷新吗? – 2013-02-15 11:27:02

+0

什么样的变化?一个新的URL,还是一个锚点? – 2013-02-15 11:27:27

+0

男人我认为你正在检测hashchange。 – 2013-02-15 11:27:39

回答

0

尝试

$(document).ready(function() { 
    $(window).bind('hashchange', function(e) { 
    var anchor = document.location.hash; 
      if(anchor === '#first_one') { 
       alert('url = #first'); 
      }else if (anchor === '#second_one') { 
       alert('url = #second'); 
      }else if (anchor === '#third_one') { 
       alert('url = #third'); 
      } 
      console.log(anchor); 
    }); 
});

not working in all browser

jquery-hashchange-plugin

+0

我试图检测一个框架是否想要突破并将主页面重定向到另一个URL。 – indect 2013-02-15 11:42:14

+1

@indect所以请更新所有需求的问题,以便OtherPeople也可以帮助... thanx – 2013-02-15 11:44:40