XMen
XMen

Reputation: 30248

How can I decode a URL with jQuery?

How can I decode a URL using jQuery? My url is

http%3A%2F%2Fdtzhqpwfdzscm.cloudfront.net%2F4ca06373624db.jpg

Upvotes: 48

Views: 98410

Answers (5)

Jpsy
Jpsy

Reputation: 20852

If you URL should also contain blanks encoded as '+', the following call will help (taken from https://stackoverflow.com/a/4458580/430742):

decodeURIComponent((str+'').replace(/\+/g, '%20'))

Upvotes: 4

Darin Dimitrov
Darin Dimitrov

Reputation: 1038850

Try the decodeURIComponent function:

var decodedUri = decodeURIComponent('http%3A%2F%2Fdtzhqpwfdzscm.cloudfront.net%2F4ca06373624db.jpg');
alert(decodedUri);

Upvotes: 106

Doug
Doug

Reputation: 5318

You can simply call the standard javascript functions for encoding and decoding respectively.

encodeURIComponent
decodeURIComponent

Enjoy!

Upvotes: 7

Nick Craver
Nick Craver

Reputation: 630429

Use decodeURIComponent(), for example:

decodeURIComponent("http%3A%2F%2Fdtzhqpwfdzscm.cloudfront.net%2F4ca06373624db.jpg")

It's not jQuery specific, this is a base JavaScript function.

Upvotes: 13

reko_t
reko_t

Reputation: 56430

decodeURIComponent('http%3A%2F%2Fdtzhqpwfdzscm.cloudfront.net%2F4ca06373624db.jpg')

Upvotes: 1

Related Questions