开发者

How can I decode a URL with jQuery?

开发者 https://www.devze.com 2023-01-17 13:57 出处:网络
How 开发者_StackOverflow中文版can I decode a URL using jQuery? My url is http%3A%2F%2Fdtzhqpwfdzscm.cloudfront.net%2F4ca06373624db.jpg

How 开发者_StackOverflow中文版can I decode a URL using jQuery? My url is

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


Try the decodeURIComponent function:

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


Use decodeURIComponent(), for example:

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

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


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

encodeURIComponent
decodeURIComponent

Enjoy!


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'))


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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号