User:Glazou

Not implemented, update template.

Convert a JS string into UTF-8

Suppose you have a JS string and need to encode it into UTF-8. A good example is the twitter API that allows you to post a message. The text of the message must be added to the POST url using the 'status' parameter and the contents of that parameters must be escaped UTF-8. Use the following code to convert your text to UTF-8:

function JSStringToUTF8(aStr) {

  var converter = Components.classes["@mozilla.org/intl/scriptableunicodeconverter"]
                    .createInstance(Components.interfaces.nsIScriptableUnicodeConverter);

  converter.charset = "utf-8" ;

  return converter.ConvertFromUnicode(aStr);
}

 

Document Tags and Contributors

 Contributors to this page: Glazou, Admin
 Last updated by: Glazou,