我试图在URL中对法语字符进行编码。
url是用javascript构造的,然后我使用window.open打开url。
例如,
var alt_title='Thierry Frémaux: Les confiden'window.open('http://example.com/alt_title'=+encodeURIComponent(altCatTit));window.open(encodeURI('http://example.com/alt_title='+encodeURIComponent(altCatTit))当1.执行时,我看不到新弹出的url中编码的法语字符。
当2.执行时,我确实看到它们正在被编码。
请您告诉我,为什么我需要对它们进行两次编码才能使它们在新弹出的URL中显示为编码?
这是在URL中编码特殊字符的正确方式吗?
修正了错误很抱歉!
发布于 2013-05-20 17:38:12
你在找这个吗?
var s = 'Thierry Frémaux: Les confiden'
var url = 'http://example.com/?alt_title=' + encodeURIComponent(s)发布于 2014-12-10 12:42:59
encodeURIComponent():假定它的参数是URI的一部分(例如协议、主机名、路径或查询字符串)。因此,它转义用于分隔URI的portionsof的标点符号。
encodeURI():用于编码现有的url
https://stackoverflow.com/questions/16654851
复制相似问题