I am attempting to retrieve the hash value for the current page without success. I target a page with a link like this;
http://www.mydomain.com/test.html#hash
My jquery for test.html looks like this;
$(document).ready(function() {
if (window.location.hash){
console.log ("FOUND HASH");
}else{
console.log ("HASH NOT FOUND");
}
});
No matter what I do, I never get the hash value; it is always empty "". However when I break on the code with Firebug and view the DOM, I can clearly see the hash value is set properly under window.location.hash.
What am I doing wrong?
Thanks in advance for the help.
ANSWER SUMMARY: It turns out cloaking my web address creates a frame wrapper around the entire page and in this case with different ports. The hash was kept by the parent frame but lost to the child and is not accessible by the jquery code. Using the direct non-cloaded address yielded correct behavior.
alert(window.location.hash). I'm sure there must be some syntax error because this should work... what browser are you using? what other context can you give us?frameandframesetobsolete elements. w3.org/TR/html5-diff/#obsolete-elements