开发者

Strange result when reading data from browser cache

开发者 https://www.devze.com 2023-04-06 19:37 出处:网络
In an experimental extension I am working on I use a function to get the source of a webpage and assign it to a variable. It worked perfectly fine. However I want to change the way it w开发者_StackOve

In an experimental extension I am working on I use a function to get the source of a webpage and assign it to a variable. It worked perfectly fine. However I want to change the way it w开发者_StackOverflow中文版orks and get the content from a txt file.

I am hosting a txt file like: http//1.2.3.4/1.txt.

What I want is to assign the contents of this txt file to a variable.

Function is here: http://jsfiddle.net/qumsm/.

(Function is not mine. I got it from another extension xpi which I cant remember right now. Respects to the coder of it.)

The function produces "ÿþP" this result which I dont get.


That's a byte order mark, the file you are looking at seems to be using UTF-16 LE encoding. You need to use nsIConverterInputStream instead of nsIScriptableInputStream when reading in that data and specify the correct encoding to convert from. nsIScriptableInputStream is only useful when reading in ANSI data, not Unicode. See code example on MDN.

0

精彩评论

暂无评论...
验证码 换一张
取 消