| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/encodeURI | [Back] [Original] |
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. Its 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);
URIURI.
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 2027 LanguageSpecification # sec-encodeuri-uri |
This page was last modified on 2026 7 15 by MDN contributors.
Your blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |