Special characters in url in Safari

廉价感情. 提交于 2019-12-04 10:02:27

Finally I found the solution. If set hash through window.location.href everything works fine.

Here is the code:

var newHash = ...
var sharpIdx = window.location.href.indexOf("#");
if (sharpIdx === -1) {
  window.location.href = window.location.href + "#" + newHash;
} else {
  window.location.href = window.location.href.substr(0, sharpIdx) + "#" + newHash;
}

I have faced same issue, found another workaround

window.location.hash = path;
// For safari url change fix
if (window.location.hash !== path) {
    window.location.hash = encodeURI(path);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!