How To Convert DOM Node Text Value To UTF-8 In JavaScript?
I need to send a text content of an HTML node over Ajax request, but first convert it to UTF-8. Is that possible? Thanks!
Solution 1:
function encode_utf8( s )
{
return unescape( encodeURIComponent( s ) );
}
function decode_utf8( s )
{
return decodeURIComponent( escape( s ) );
}
from http://ecmanaut.blogspot.com/2006/07/encoding-decoding-utf8-in-javascript.html
use it like this...
encode_utf8(document.getElementById(id).textContent);
Post a Comment for "How To Convert DOM Node Text Value To UTF-8 In JavaScript?"