I have a simple javascript function to get hash variables:
$(document).ready(function(){
$("a").click(function(){
nav_anchor()
});
function nav_anchor() {
var aurl = location.hash;
aurl = aurl.split('#');
if (aurl[1]) { alert(aurl[1]); }
else { alert("Empty"); }
}
});
<a href="#a=1&aa=10">11111111111</a>
<a href="#b=1&bb=10">22222222222222</a>
<a href="#c=1&cc=10">333333333</a>
But if I click in the link I receive the previous var.
Example:
If my first Click is 11111 I receive message Empty and if my second click is 222222 I receive a=1&aa=10
http://jsbin.com/uxitoy/2/edit
$(document).ready(function(){
$("a").click(function(){
nav_anchor(this);
});
function nav_anchor(o) {
var aurl = o.hash;
aurl = aurl.split('#');
if (aurl[1].length>0) { alert(aurl[1]); }
else { alert("Empty"); }
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With