![](/img/trans.png)
[英]Javascript: encodeURI() / encodeURIComponent() charset
[英]encodeURIComponent and encodeURI
我正在嘗試對URL中的法語字符進行編碼。
該網址是用javascript構建的,然后我使用window.open
打開該網址。
例如,
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中編碼特殊字符的正確方法嗎?
解決了錯字的問題!
你在找這個嗎?
var s = 'Thierry Frémaux: Les confiden'
var url = 'http://example.com/?alt_title=' + encodeURIComponent(s)
encodeURIComponent():假定其參數是URI的一部分(例如協議,主機名,路徑或查詢字符串)。 因此,它轉義了用於分隔URI部分的標點符號。
encodeURI():用於對現有網址進行編碼
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.