有什么方法可以检测 jQuery 中 top.location.href 或 window.location.href 的变化?尝试过类似的东西
top.location.href.change(function() {});
已经,但是没有用。
有任何想法吗?
更新:我想防止框架打破盒子。框架可能不会更改主页的 top.location.href。
谢谢!检测
尝试
$(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);
});
});