How to decode url encoded string in javascript

I use javascript / jquery to populate dom elements containing umlauts:

var text1 = "Unser platonisches Internetreich droht in die H%E4nde einer bewaffneten Miliz zu fallen." $("#quote1 span").html(unescape(text1)); 

How can I get rid of url encoding? "H% E4nde" and use "HΓ€nde" instead? I tried

 <meta charset="utf-8" /> <meta name="http-equiv" content="Content-type: text/html; charset=UTF-8"/> <script type="text/javascript" src="js/index.js" charset="utf-8"></script> 

But none of them seem to work ...

Thanks for the help.

+4
source share
1 answer

This is not UTF-8, i.e. percent encoding , also known as url encoding.

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

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

+18
source

Source: https://habr.com/ru/post/1481716/


All Articles