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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With