-2

I'm beginner in Javascript, I have a url containing unicode like below:

/Solutions/راه-کار-جامع-امنیت-اطلاعات 

Now I need to read the path name by following code

window.location.pathname.split('/')

and in the output I have this

"", "Solutions", "%D8%B1%D8%A7%D9%87-%DA%A9%D8%A7%D8%B1-%D8%AC%D8%A7…%D8%AA->%D8%A7%D8%B7%D9%84%D8%A7%D8%B9%D8%A7%D8%AA"

How can I solve this problem?

GolezTrol
  • 114,394
  • 18
  • 182
  • 210
LA SN
  • 555
  • 4
  • 6
  • 1
    Those are the properly URL-encoded values for the characters outside of the ASCII range that are not allowed directly in a URL. If you want the original characters again, then URL-decode either the single values each, or the URL before you split it. Go look up `decodeURIComponent`. – CBroe Sep 13 '14 at 11:50

1 Answers1

1

The unicode text is url-encoded. This means that the unicode characters are translated to codes that are safe to use as a url. You can revert this using the decodeURIComponent or the decodeURI function.

The difference between these two is already nicely explained in this question. In your case you will most likely use decodeURIComponent after you performed the split.

Community
  • 1
  • 1
GolezTrol
  • 114,394
  • 18
  • 182
  • 210