The goal: Correctly put a string from a data
attribute into the window.location.hash
.
The code:
map = {path: $(this).attr('data-path'), rev: $(this).attr('data-rev')};
window.location.hash = getMapParams(map);
function getMapParams(map) {
s="";
for(key in map) {
value=eval("map."+key);
if (s.length > 0) {
s+="&";
}
s+=encodeURIComponent(key)+"="+encodeURIComponent(value);
}
return s;
}
The problem: As soon as the data-path
attribute contains a space Firefox fails to put the hash correctly. The space will appear unencoded whereas in other browsers it's correctly encoded as %20
.
The weird quirks: If I debug the code the string is listed with the encoded space.
The research done: I have found plenty solutions for correctly reading the hash in firefox. In one way or another this is working fine with my code.
The question: How do I stop Firefox from urldecoding the space(s) in a string I put in window.location.hash
id=""
and scroll the page for you. Can't you use_
or something instead?/
(%2F
) are left as is..