简体   繁体   中英

URL.createObjectURL and charset UTF-8

i have problem with encoding my text

 var description = "jak używać?" var blob = new Blob([description], { type: "text/plain;charset=utf-8;" }); var url = URL.createObjectURL(blob); console.log(url) 

where i enter to url my description isnt same and return jak uĹźywaÄ? What i doing wrong?

Add Byte order mark to the array header.

blob = new Blob(["\ufeff", description]);

https://stackoverflow.com/a/18925211/9867895

https://en.wikipedia.org/wiki/Byte_order_mark

URL.creatObjectUrl doesn't seem to work with raw UTF-8 strings. The solution provided for binary data https://stackoverflow.com/a/36955941/70716 should work. the answers to Creating a Blob from a base64 string in JavaScript also include some additional explanation of the issue and alternative code examples.

Try:

...

var blob = new Blob([**"\ufeff",** description], {

...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM