Friday, August 14, 2009

How to decode utf-8 entities in javascript

Let's say a request comes back from the server with ø in the response (which is gzip encoded because it is an AJAX call). A quick and dirty way to decode this entity in javascript is:

var encodedText = 'Gøøøse'

var temp = document.createElement('span');
temp.innerHTML = encodedText;
var decodedText = temp.innerHTML;
temp = null;

this will set decodedText to: 'Gøøøse'

No comments:

Post a Comment