Tag Archives: cyrillic

JavaScript encode cyrillic symbols with encodeURIComponent

JavaScript and Cyrillic

Let’s assume we’ve a JavaScript file which rewrites the location.href, resulting in changes in the URI of the browser. Everything is OK till you work with Latin alphabet. The problem arises when you decide to put some Cyrillic symbols into the string.

The encode() function

With that function you can encode the URL if you have some entity symbols. It is not like but it should be something like encodeURI in PHP. The problem is that this function does not work correctly with Cyrillic symbols.

Use encodeURIComponent

There is another usefull function which does this. It’s called encodeURIComponent, and I strongly recomment its use.