开发者

What can cause a URL hash to change?

开发者 https://www.devze.com 2023-03-16 17:41 出处:网络
I\'m trying to monitor my URL hash (a.k.a. fragment) using the onh开发者_JAVA百科ashchange event so that I can make appropriate ajax calls based upon the parameters I\'m storing in the hash.Unfortunat

I'm trying to monitor my URL hash (a.k.a. fragment) using the onh开发者_JAVA百科ashchange event so that I can make appropriate ajax calls based upon the parameters I'm storing in the hash. Unfortunately, there is something unexpected changing my hash. In all of my code, there is only one place that where I use window.location.hash and it is simply checking the value of the hash, not changing it. I know that the back and forward buttons can change the hash, but I'm not touching them. How do I find where the hash change is coming from?


Update

Ok... figured it out. And yes, I'm a dummy, but I leave my findings here for those as dumb as I. I was looking for something programmatic changing my hash, but what was really happening was that I was clicking on an anchor with href="#". There is an event handler hooked to these, and I set the return value to false and that prevented it from changing the URL.


Links that target internal anchors change the hash. For example:

<a href="#contact">Contact Us</a>

Clicking that would change the hash to #contact.

Also, if you're using any third-party javascript libraries, it's possible that some code in there might be changing it.

What does the hash change to? From what? And When? If you can identify the exact circumstances that trigger the change, that should give you some idea what might be changing it.

0

精彩评论

暂无评论...
验证码 换一张
取 消