I have the following URL in the browser address bar:
example.com/search/city/Germany:Baden-Württemberg
From the console I try to get the pathname of the URL:
location.pathname
which returns:
/search/city/Germany:Baden-Württemberg
I see that the ü character has been transformed (escaped) to ü sequence. I want to dysplay this character as is in the HTML document, therefore I tryed with unescapeing it:
unescape(location.pathname)
but unfortunatelly what I get is not the string from the URL >
'/search/city/Germany:Baden-Württemberg'
How can I get the URL character ü (from my URL example.com/search/city/Germany:Baden-Württemberg
) via Javascript ?
Thank you!
CodePudding user response:
The solution pointed out by @Cid
Use decodeURI()
worked better in this case than unescape
which seems not to be the preferred function for such translations.
Usually, decodeURI or decodeURIComponent are preferred over unescape.
Again, all the credits of this answer go to @Cid for his comments on the original questions.