我剥离与“document.location.hash”的网址,并试图检查当前网址留下什么。我不想使用任何插件,也不想从点击等触发事件中学习结果。需要立即和现代地学习网址变化。如何检测当前的网址当发生任何变化
的jQuery:
$(function() {
$(document).location().change(function() {//this part is not working
var anchor = document.location.hash;
if(anchor === '#one') {
alert('current url = #one');
}else if (anchor === '#two') {
alert('current url = #two');
}else if (anchor === '#three') {
alert('current url = #three');
}
console.log(anchor);
});
});
HTML:
<a href="#one">one</a>
<a href="#two">two</a>
<a href="#three">three</a>
深注:我已阅读这些问题和cout找到我在寻找: How to detect URL change in JavaScript + How to change the current URL in javascript?
取决于什么浏览器barlasapaydin想支持(http://caniuse.com/hashchange) – voigtan 2012-07-17 15:33:03
完全..看到更新的答案 – BumbleB2na 2012-07-17 15:33:27