How can I decode a URL with jQuery?

前端 未结 5 953
独厮守ぢ
独厮守ぢ 2020-12-05 06:20

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

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

相关标签:
5条回答
  • 2020-12-05 06:56

    Use decodeURIComponent(), for example:

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

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

    0 讨论(0)
  • 2020-12-05 07:01

    Try the decodeURIComponent function:

    var decodedUri = decodeURIComponent('http%3A%2F%2Fdtzhqpwfdzscm.cloudfront.net%2F4ca06373624db.jpg');
    alert(decodedUri);
    
    0 讨论(0)
  • 2020-12-05 07:04

    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'))
    
    0 讨论(0)
  • 2020-12-05 07:07

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

    encodeURIComponent
    decodeURIComponent
    

    Enjoy!

    0 讨论(0)
  • 2020-12-05 07:18
    decodeURIComponent('http%3A%2F%2Fdtzhqpwfdzscm.cloudfront.net%2F4ca06373624db.jpg')
    
    0 讨论(0)
提交回复
热议问题