Unicode and URI encoding, decoding and escaping in JavaScript
        Posted  
        
            by apphacker
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by apphacker
        
        
        
        Published on 2010-04-07T22:59:53Z
        Indexed on 
            2010/04/07
            23:03 UTC
        
        
        Read the original article
        Hit count: 352
        
If you look at this table here, it has a list of escape sequences for Unicode characters that don't actually work for me.
For example for "%96", which should be a –, I get an error when trying decode:
decodeURIComponent("%96");
URIError: URI malformed
If I attempt to encode "–" I actually get:
encodeURIComponent("–");
"%E2%80%93"
I searched through the internet and I saw this page, which mentions using escape and unescape with decodeURIComponent and encodeURIComponent respectively. This doesn't seem to help because %96 doesn't show up as "–" no matter what I try and this of course wouldn't work:
decodeURIComponent(escape("%96));
"%96"
Not very helpful.
How can I get "%96" to be a "–" with JavaScript (without hardcoding a map for every single possible unicode character I may run into)?
© Stack Overflow or respective owner