Get to know MDN better
This page was translated from English by the community. Learn more and join the MDN Web Docs community.
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2015년 7월.
encodeURIComponent() 함수는 URI의 특정한 문자를 UTF-8로 인코딩해 하나, 둘, 셋, 혹은 네 개의 연속된 이스케이프 문자로 나타냅니다. (두 개의 대리 문자로 이루어진 문자만 이스케이프 문자 네 개로 변환됩니다.)
URI 구성요소.
주어진 문자열을 URI 구성요소로서 인코딩한 새로운 문자열.
encodeURIComponent()는 다음 문자를 제외한 문자를 이스케이프 합니다.
Not Escaped: A-Z a-z 0-9 - _ . ! ~ * ' ( )encodeURIComponent()와 encodeURI()의 차이는 다음과 같습니다.
상위-하위 쌍을 이루지 않은 단일 대리 문자를 인코딩 시도하면 URIError가 발생합니다.
encodeURIComponent()를 사용해, 서버에 POST로 요청할 양식 필드를 인코딩 하세요. 입력 중 의도치 않게 생성될 수 있는 HTML 특수 개체 등의 "&" 문자를 처리할 수 있습니다.
예를 들어 사용자가 입력한 "Jack & Jill"은 "Jack & Jill"로 인코딩 됩니다. encodeURIComponent()를 사용하지 않았다면 서버가 앰퍼샌드를 새로운 필드의 시작으로 인식할 수 있으므로 데이터의 무결성을 해칠 수 있습니다.
application/x-www-form-urlencoded의 스페이스는 "+"로 치환되어야 하므로, encodeURIComponent()의 결과에 추가로 "%20"을 "+"로 바꾸세요.
비록 URI의 구분자로서 형식화된 사용처는 없지만, 그럼에도 !, ', (, ), *을 추가로 예약하는 RFC 3986을 엄격하게 따르려면 아래의 코드를 사용해보세요.
다음 예제는 UTF-8 Content-Disposition 과Link 서버 응답 헤더에서 (UTF-8 파일 이름 등의 이유로) 필요한 문자 인코딩 방법을 보입니다.
| ECMAScript® 2027 Language Specification # sec-encodeuricomponent-uricomponent |
Enable JavaScript to view this browser compatibility table.
This page was last modified on 2025년 2월 11일 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.