Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript: Replace hexadecimal character

Tags:

javascript

url

I have a string such as "%2Fu%2F2069290%2F" in JavaScript (extracted from a web page). How do I get the human-readable version of that string?

like image 522
Deniz Dogan Avatar asked Feb 02 '10 18:02

Deniz Dogan


2 Answers

Short version: Use decodeURIComponent().

Longer version: In older versions of JavaScript you could use unescape() but that has been deprecated since it only works properly for the LATIN1/ISO8859-1 codeset, so you really want to use decodeURIComponent() which is supported by all modern browsers.

 var c = decodeURIComponent("%2Fu%2F2069290%2F"));
like image 164
Johan Dahlin Avatar answered Sep 29 '22 17:09

Johan Dahlin


alert(decodeURIComponent("%2Fu%2F2069290%2F"));
like image 33
Darin Dimitrov Avatar answered Sep 29 '22 18:09

Darin Dimitrov