且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用纯JavaScript将GBK转换为UTF8?

更新时间:2023-11-27 11:13:22

http://www.1kjs.com/lib/widget/gbk /



有一个javascript可以在gbk和unicode之间进行转换: 将所有21886 gbk中文字符映射到unicode您可以下载 javascript文件,包含它并使用:


unicode to gbk:


$ URL.encode(unicode_string)


或gbk to unicode:


$ URL.decod e(gbk_string)


我测试了它。在我的网站上工作得很好:zhuhaiyang.sinaapp.com/base64/index.html



使用纯javascript做base64。。。


I want to load some text from other site wich the content is GBK encoded, but my site is UTF8.

Is there anyway by which I can convert these GBK text into UTF8 for display ?

For some reasons I can only use Javascript for this.

http://www.1kjs.com/lib/widget/gbk/

There is a javascript to convert between gbk and unicode: which maps all the 21886 gbk Chinese chars to unicode

You can simply download the javascript file , include it and using :

unicode to gbk:

$URL.encode(unicode_string)

or gbk to unicode:

$URL.decode(gbk_string)

I tested it. It's working well on my web : zhuhaiyang.sinaapp.com/base64/index.html

which do base64 ency using pure javascript.