Kay Kay - 4 months ago 78
Javascript Question

Adding UTF-8 BOM to string/Blob

I need to add a UTF-8 byte-order-mark to generated text data on client side. How do I do that?

Using

new Blob(['\xEF\xBB\xBF' + content])
yields
'"my data"'
, of course.

Neither did
'\uBBEF\x22BF'
work (with
'\x22' == '"'
being the next character in
content
).

Is it possible to prepend the UTF-8 BOM in JavaScript to a generated text?

Yes, I really do need the UTF-8 BOM in this case.

Answer