user852367 user852367 - 3 years ago 253
HTML Question

Decoding URL parameters with JavaScript

This should simple task, but I can't seem to find a solution.

I have a basic string that is being passed through as a query string parameter like this one:

. I would like to decode that parameter using Javascript to
This is a message with spaces
, but I cannot seem to get it to decode.

I've tried
but the result still contains the

Any help would be appreciated. Thank you!

Answer Source

The plus sign is not encoded/decoded. To see the decode function working, you need to pass a encoded URI first. Take a look:

encodeURI( " bar jar" )

Will generate:, i.e., the encoded URI.

decodeURI( "" )

Will generate: bar jar, i.e., the decoded URI.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download