gpt4 book ai didi

javascript - window.location.hash 的编码

转载 作者:IT王子 更新时间:2023-10-29 03:07:54 27 4
gpt4 key购买 nike

window.location.hash 是否包含 url 部分的编码或解码表示?

当我打开相同的 url (http://localhost/something/#%C3%BC 其中 %C3%BC 转换为 ü) 在 Firefox 3.5 和 Internet Explorer 8 中,我得到了不同的 document.location.hash 值:

  • IE8: #%C3%BC
  • FF3.5:

有没有办法在两种浏览器中获得一个变体?

最佳答案

不幸的是,这是 Firefox 中的一个错误,因为它会在访问时额外解码 location.hash。例如,在 Firefox 中试试这个:

location.hash = "#%30";
location.hash === "#0"; // This is wrong, it should be "#%30"

唯一的跨浏览器解决方案是只使用 (location.href.split("#")[1] || "") 而不是获取哈希。不过,使用 location.hash 设置散列似乎适用于所有支持 location.hash 的浏览器。

关于javascript - window.location.hash 的编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1703552/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com