3

I am working on a browser plugin that takes the URL of the current page or any selected link as a parameter and send it to our server. When characters of the basic latin alphabet are present in the url (like http://en.wikipedia.org/wiki/Vehicle), the plugin works fine. However, when the URL contains characters from another alphabet such as http://ru.wikipedia.org/wiki/Коляска the plugin does not work, I do use the encodeURIComponentmethod but that does not seem to solve the issue. Any idea?

Thanks,

Olivier.

Olivier
  • 305
  • 1
  • 4
  • 17
  • 2
    http://ru.wikipedia.org/wiki/Коляска is not really a valid URL. When you enter that into a modern browser, it will URLEncode the characters automatically. Can you explain in more detail what you are doing, where the data is coming from, and what `encodeURIComponent` does that doesn't suit? Also, what do you mean by "browser plugin" exactly? – Pekka Sep 14 '10 at 19:20
  • 1
    Background: http://stackoverflow.com/questions/2742852/unicode-characters-in-urls – Pekka Sep 14 '10 at 19:21

2 Answers2

1

You probably want to use encodeURI/decodeURI, if you are trying to take a full URI with non-ASCII characters and translate it into its encoded form. These preserve special URI characters, such as : and /, instead of escaping them; it only escapes non-ASCII characters and characters that are invalid in URIs. Thus, they do essentially the same thing as typing in the address bar or putting a URI in an <a href="..."> (though the behavior might vary somewhat between browser, and isn't exactly the same).

encodeURIComponent is intended for encoding only a single component of a URI, replacing special characters that are meaningful in URIs, so that you can use the component as a query parameter or path component in a longer URI.

Brian Campbell
  • 322,767
  • 57
  • 360
  • 340
0

This one says it covers UTF-8. http://www.webtoolkit.info/javascript-url-decode-encode.html. Might solve your problem

Brandon Boone
  • 16,281
  • 4
  • 73
  • 100