are there character set restrictions or autoconversion oddities for location.hash?
i want to store and retrieve data via the url hash. the user is able to make some dropdown settings on the page, which should get written into the url via the location.replace
function*.
for simplicity’s sake, it now works like this: initially, the user is on test.com
. after changing two settings, the url looks like this: http://test.com#fruit→banana#color→light blue
.
another almost as simple way would be http://test.com#fruit=banana, color=light blue
. the only characters the settings and options contain are (as regular expression) [A-Za-z &]
as far as i can tell, this works fine, although firefox url-escapes everything on copying, and chrome doesn’t. after pasting and pressing enter, the url bar shows the unescaped hash, fetching location.hash
per javascript also gives the unescaped unicode string.
my question: are there any probblems, inconsistencies, or other quirks 开发者_开发百科i don’t know about?
*FYI: location.replace("#hash")
works just like one would expect :D
As i already noted in the comment, forget
location.hash
and use
location.href.replace(/^[^#]+/,'');
instead.
It will save you a whole heap of trouble.
精彩评论