Can’t determine how data is being encoded

I have a web form that was written a while ago that I’m trying to interface with – I don’t have access to change it. I need to be able to interface with it through javascript, but I’m struggling to get javascript to encode the data in the right way. It looks like EVERYTHING that is not [A-Za-z0-9] is encoded, but I can’t find a javascript function that’ll do the same thing. Test case:

Input: [email protected]="'()_ (there’s a space at the end)

Desired output: %7E%2B%40%2D%3D%22%27%27%28%29%5F%20

escape: %[email protected]%3D%22%27%28%29_%20

encodeURI: [email protected]=%22'()_%20

encodeURIcomponent: ~%2B%40-%3D%22'()_%20

Note than I’m (shudder) using IE10. Also not changeable. (I’m no more happy about this than you are.)

Any suggestions? (Preferably vanilla)


It looks as though it is the Hex equivalent

~       = 7E
+       = 2B
@       = 40
-       = 2D
=       = 3D
"       = 22
'       = 27
(       = 28
)       = 29
_       = 5F
space   = 20

You should be able to use to charCodeAt to encode these values

    // -> returns '7E'


• ASCII codes are here:

• string(16) means base 16, which is hexadecimal

Leave a Reply

Your email address will not be published. Required fields are marked *