Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript: encodeURI() / encodeURIComponent() charset

Is there any way to specify charset in Javascript's encodeURI() or encodeURIComponent()? E.g.:

encodeURIComponent("例子", "UTF-8") outputs %E4%BE%8B%E5%AD%90

encodeURIComponent("例子", "GBK") outputs %C0%FD%D7%D3

like image 599
optimizitor Avatar asked Oct 06 '22 01:10

optimizitor


1 Answers

My solution is to used a npm package urlencode and browserify.

Write in urlencode.js:

var urlencode = require("urlencode");
module.exports = function (s) { return urlencode(s, "gbk"); }

browserify urlencode.js --s encode > bundle.js

And in bundle.js, a function called encode is declared.

like image 160
Endle_Zhenbo Avatar answered Oct 13 '22 10:10

Endle_Zhenbo