Skip to content Skip to sidebar Skip to footer

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:

functionencode_utf8( s )
{
  returnunescape( encodeURIComponent( s ) );
}

functiondecode_utf8( s )
{
  returndecodeURIComponent( 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?"