问题描述
window.location.hash
是否包含url部分的编码或解码表示?
当我打开相同的网址( http:// localhost / something /#%C3%BC
其中%C3%BC
翻译在Firefox 3.5和Internet Explorer 8中的ü
中,我获得 document.location.hash
的不同值: p>
- IE8:
#%C3%BC
- FF3.5:
#ü
有没有办法得到一个两个浏览器中的变体?
不幸的是,这是Firefox中的一个错误,因为它解码了 location.hash
访问一个额外的时间。例如,在Firefox中尝试:
location.hash =#%30;
location.hash ===#0; //这是错的,它应该是#%30
唯一的跨浏览器解决方案是要使用(location.href.split(#)[1] ||)
代替获取散列。对于支持 location.hash
的所有浏览器,使用 location.hash
设置哈希值。
Does window.location.hash
contain the encoded or decoded representation of the url part?
When I open the same url (http://localhost/something/#%C3%BC
where %C3%BC
translates to ü
) in Firefox 3.5 and Internet Explorer 8, I get different values for document.location.hash
:
- IE8:
#%C3%BC
- FF3.5:
#ü
Is there a way to get one variant in both browsers?
Unfortunately, this is a bug in Firefox as it decodes location.hash
an extra time when it is accessed. For example, try this in Firefox:
location.hash = "#%30";
location.hash === "#0"; // This is wrong, it should be "#%30"
The only cross-browser solution is to just use (location.href.split("#")[1] || "")
instead for getting the hash. Setting the hash using location.hash
seems to work correctly for all browsers that support location.hash
though.
这篇关于window.location.hash的编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!