How to decode url-encoded string in javascript

后端 未结 2 659
名媛妹妹
名媛妹妹 2020-12-11 02:33

I use javascript / jquery to fill dom elements that contain umlauts:

var text1 = \"Unser platonisches Internetreich droht in die H%E4nde einer bewaffneten Mi         


        
相关标签:
2条回答
  • 2020-12-11 03:00

    Use either of the following built in JavaScript function to decode any encoded text. No need for jquery or any other library.

    const text1 = "Unser platonisches Internetreich droht in die H%E4nde einer bewaffneten Miliz zu fallen."
    
    console.log(decodeURI(text1))
    
    console.log(decodeURIComponent(text1))
    
    0 讨论(0)
  • 2020-12-11 03:04

    That is not UTF-8, that is percent encoding also known as url encoding.

    You can use decodeURIComponent() to convert it back before displaying it

    $("#quote1 span").html(decodeURIComponent(text1));

    0 讨论(0)
提交回复
热议问题