Special characters in URLs in Safari

We use some special characters in our web application as follows: example.com/foo# .

We analyze the hash with decodeURI(window.location.hash) (and sometimes the hash contains non-encoded special characters) and set the new value as window.location.hash = "" .

Everything works fine in Chrome, Firefox, Opera and even IE, but in Safari we get 20? instead of .

If the specified hash is in Safari, for example, window.location.hash = encodeURI(""); It works, but of course it does not work in Chrome, FF and others.

+4
source share
2 answers

Finally, I found a solution. If set hash via 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; } 
+5
source

I ran into the same problem, found another workaround

 window.location.hash = path; // For safari url change fix if (window.location.hash !== path) { window.location.hash = encodeURI(path); } 
0
source

All Articles