开发者

firefox addon development and Unicode

So I started开发者_如何学Python developing my firefox addon. Most of the work is performed by a referenced javascript file. Problem is that when I edit some of the html elements on the page and say, set their text it's written as pure giberish. I am writing the text in hebrew. Can't for the life of me figure the reason.

Any ideas?


Javascript strings are already Unicode at runtime. However, you have to make sure that your files are encoded correctly.

Always use utf-8 (without BOM) file encoding for all your js, XUL, DTD, properties files to be sure. Firefox might try to guess the file character set incorrectly otherwise, and even worse some stuff might not even try guessing the encoding and instead simply always assume utf-8.

Better yet, do not hard-code strings in js/xul, but use DTD/properties files for localization (XUL tutorial, XUL School).

This, e.g. snippet works pretty well for me (on this very page):

document.getElementsByTagName("h1")[0].textContent="русский язык";

(Just fire up the Firefox Web Console)

"Inline" hewbrew embedded in js files might create additional problems because it is right-to-left and bidi sucks, so the localization approach should be preferred.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜