How can I decode a URL that is not encoded in UTF8 using firefox addons api?

I am trying to write a firefox addon and just met this problem.

Firefox seems to encode the search engine URL using the encoding of the website, suppose we have the word "", which means the fire is in Chinese, and we search for it using google, the URL

http://www.google.com/search?q=g+火&ie=utf-8 ... 

This url is decoded / not tied to UTF8, but if I go to Baidu, the Chinese search engine whose encoding is gb2312, we get the url

http://www.baidu.com/s?wd=%BB%F0

Here BBF0 is gb2312 code for '火',

How can I get a UTF8 character from some encoding (gbk, jp or something else) with firefox API? I went through the nsIScriptableUnicodeConverter part on develop.mozilla.org and just can't find a suitable way to do this.

+3
1

, , firefox URL-,

var converter = Components.classes["@mozilla.org/intl/scriptableunicodeconverter"].createInstance(Components.interfaces.nsIScriptableUnicodeConverter);
converter.charset = "gbk";
var car = "%D6%D0%B9%FA";
alert(converter.ConvertToUnicode(unescape("%D6%D0%B0%FA")));

...

+1

All Articles