encodeURI()
Baseline
Widely available
This feature is well established and works across many devices and browser versions. Itâs been available across browsers since â¨2015ë 7ìâ©.
encodeURI() í¨ìë URIì í¹ì í 문ì를 UTF-8ë¡ ì¸ì½ë©í´ íë, ë, ì
, í¹ì ë¤ ê°ì ì°ìë ì´ì¤ì¼ì´í 문ìë¡ ëíë
ëë¤. (ë ê°ì ë리 문ìë¡ ì´ë£¨ì´ì§ 문ìë§ ì´ì¤ì¼ì´í 문ì ë¤ ê°ë¡ ë³íë©ëë¤.)
ìëí´ ë³´ê¸°
const uri = "https://mozilla.org/?x=ÑеллÑ";
const encoded = encodeURI(uri);
console.log(encoded);
// Expected output: "https://mozilla.org/?x=%D1%88%D0%B5%D0%BB%D0%BB%D1%8B"
try {
console.log(decodeURI(encoded));
// Expected output: "https://mozilla.org/?x=ÑеллÑ"
} catch (e) {
// Catches a malformed URI
console.error(e);
}
구문
encodeURI(URI);
매ê°ë³ì
URI-
ìì í URI.
ë°í ê°
주ì´ì§ 문ìì´ì URIë¡ì ì¸ì½ë©í ìë¡ì´ 문ìì´.
ì¤ëª
encodeURI() í¨ìë URIìì í¹ë³í ë»ì ê°ì§ 문ì(ìì½ ë¬¸ì)ë ì¸ì½ë© íì§ ììµëë¤. ìë ìì ë "URI ëì"ì´ í¬í¨í ì ìë 모ë ë¶ë¶ì ë´ê³ ììµëë¤. ì¼ë¶ 문ìê° ì´ë¤ ë°©ìì¼ë¡ í¹ë³í ì미를 주ì
íê³ ìëì§ ì ì´í´ë³´ì¸ì.
http://username:password@www.example.com:80/path/to/file.php?foo=316&bar=this+has+spaces#anchor
ë°ë¼ì encodeURI()ë ìì í URI를 íì±íëë° íìí 문ìë ì¸ì½ë© íì§ ììµëë¤. ëí, ìì½ë 목ì ì ê°ì§ì§ë ìì§ë§ URIê° ê·¸ëë¡ í¬í¨í ì ìë ëª ê°ì§ 문ì("ë¹ìì½ íì")ë ì¸ì½ë© íì§ ììµëë¤. (RFC 2396ì ì°¸ê³ íì¸ì)
encodeURI() ë ë¤ì 문ì를 ì ì¸í 문ì를 ì´ì¤ì¼ì´í í©ëë¤.
ì´ì¤ì¼ì´í íì§ ìë 문ì:
A-Z a-z 0-9 ; , / ? : @ & = + $ - _ . ! ~ * ' ( ) #
encodeURI()ì encodeURIComponent()ì ì°¨ì´ë ë¤ìê³¼ ê°ìµëë¤.
var set1 = ";,/?:@&=+$#"; // ìì½ ë¬¸ì
var set2 = "-_.!~*'()"; // ë¹ìì½ íì
var set3 = "ABC abc 123"; // ìíë²³ ë° ì«ì, 공백
console.log(encodeURI(set1)); // ;,/?:@&=+$#
console.log(encodeURI(set2)); // -_.!~*'()
console.log(encodeURI(set3)); // ABC%20abc%20123 (공백ì %20ì¼ë¡ ì¸ì½ë©)
console.log(encodeURIComponent(set1)); // %3B%2C%2F%3F%3A%40%26%3D%2B%24%23
console.log(encodeURIComponent(set2)); // -_.!~*'()
console.log(encodeURIComponent(set3)); // ABC%20abc%20123 (공백ì %20ì¼ë¡ ì¸ì½ë©)
encodeURI() í¼ììë XMLHttpRequest ë±ì´ ì¬ì©í , ì í©í HTTP GETê³¼ POST ìì²ì 구ì±í ì ììµëë¤. GETê³¼ POSTìì í¹ë³í 문ìë¡ ì·¨ê¸íë "&", "+", "="를 ì¸ì½ë© íì§ ì기 ë문ì
ëë¤. ê·¸ë¬ë encodeURIComponent()ë ì ì¸ ë¬¸ìë ì¸ì½ë© ëìì í¬í¨í©ëë¤.
ìì-íì ìì ì´ë£¨ì§ ìì ë¨ì¼ ë리 문ì를 ì¸ì½ë© ìëíë©´ URIErrorê° ë°ìí©ëë¤.
// high-low pair ok
console.log(encodeURIComponent("\uD800\uDFFF"));
// lone high surrogate throws "URIError: malformed URI sequence"
console.log(encodeURIComponent("\uD800"));
// lone low surrogate throws "URIError: malformed URI sequence"
console.log(encodeURIComponent("\uDFFF"));
ëí, URLì ë³´ë¤ ìµì RFCì¸ RFC3986ì ë°ë¥´ê³ ì íë¤ë©´, ëê´í¸ê° IPv6 ì§ìì ìí´ ì¶ê°ë¡ ìì½ë¨ì ë°ë¼ encodeURI()ê° ì¸ì½ë©íì§ ìì¼ë¯ë¡ URLì ìì±í ë 주ìí´ì¼ í©ëë¤. ë¤ì ìì ì½ëê° ëìì´ ë ìë ììµëë¤.
function fixedEncodeURI(str) {
return encodeURI(str).replace(/%5B/g, "[").replace(/%5D/g, "]");
}
ëª ì¸
| Specification |
|---|
| ECMAScript® 2026 Language Specification > # sec-encodeuri-uri > |