Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
453 views
in Technique[技术] by (71.8m points)

window.open打开带中文的url出现乱码?

var href = "https://s.1688.com/selloffer/offer_search.htm?keywords=小白&sortType=va_rmdarkgmv30rt"
var href2 = encodeURI(href)  //编码了一次
window.open(href2)

我使用encodeURI编码了一次,打开搜索结果还是有问题。
image.png


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

1688的转码是GBK,encodeURI是用Unicode,这样转换出来就会乱码,你重写一个GBK编码的中文转换就可以了
`https://s.1688.com/selloffer/offer_search.htm?keywords=%D6%D0%CE%C4&sortType=1
`
中文通过encodeURI转的是 %E4%B8%AD%E6%96%87在1688就会乱码,用GBK编码转成%D6%D0%CE%C4即可


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...