0

有什么方法可以检测 jQuery 中 top.location.href 或 window.location.href 的变化?尝试过类似的东西

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

已经,但是没有用。

有任何想法吗?

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

谢谢!检测

4

1 回答 1

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

不适用于所有浏览器

jquery-hashchange-插件

于 2013-02-15T11:34:57.787 回答