Reputation: 109
I want to change pathname via function window.location.pathname. I have got this source code.
var hash = window.location.hash;
window.location.pathname = hash;
in Mozilla it works right, but in Chrome doesn't. Chrome write me this adress.
/%23!stranka=novinky&cisloStranky=1&rubrika=novinky&clanek=783?stranka=kontakty#!stranka=novinky&cisloStranky=1&rubrika=novinky&clanek=783
Value of hash is #!stranka=novinky&cisloStranky=1&rubrika=novinky&clanek=783
Have someone any idea?
Thanks.
Upvotes: 0
Views: 1575
Reputation: 8104
You'll have to understand that location.hash
includes the #
itself as well. The rest of the location.hash
is, per spec, URLencoded, but the #
isn't.
I said "per spec", as Firefox has a bug related to the location.hash
property.
If you want to change location.pathname
to the hash with the value included, you'll have to encode the #
before doing so.
Example:
var hash=location.hash.substring(1)
location.pathname='%23'+hash
If you don't want the hash to be included, just use
var hash=location.hash.substring(1)
location.pathname=hash
Upvotes: 1