Use encodeURI when you want a working URL.
Encodes a Uniform Resource Identifier (URI) by replacing each instance of certain characters by one, two, three, or four escape sequences representing the UTF-8 encoding of the character (will only be four escape sequences for characters composed of two "surrogate" characters).
[
Mozilla encodeURI
-
Mozilla decodeURI
]
var uri = 'https://mozilla.org/?x=шеллы'; var encoded = encodeURI(uri); > https://mozilla.org/?x=%D1%88%D0%B5%D0%BB%D0%BB%D1%8B var decode = decodeURI(encoded); > https://mozilla.org/?x=шеллы