728x90
SMALL
#JavaScript
#avaScript / Functions / encodeURI(), encodeURIComponent(), decodeURI(), decodeURIComponent()
encodeURI(), encodeURIComponent(), decodeURI(), decodeURIComponent()
- encodeURI() : A function that encodes without :, ;, /, =, ?, &, etc. used in internet addresses.
- encodeURIComponent() : a function that encodes all characters.
- decodeURI() : A function that decodes a string encoded with encodeURI().
- decodeURIComponent() : A function that decodes strings encoded with encodeURIComponent() .
Grammar
encodeURI( uri )
encodeURIComponent( uri )
decodeURI( uri )
decodeURIComponent( uri )
uri: Enter the internet address to encode.
example
An example of encoding and decoding a URI containing special characters and Hangul.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JavaScript</title>
<style>
body {
font-family: Consolas, sans-serif;
}
</style>
</head>
<body>
<script>
var a = 'https://www.codingfactory.net/?s=script';
var b = encodeURI( a );
var c = encodeURIComponent( a );
document.write( '<p>URI<br>' + a + '</p>' );
document.write( '<p>encodeURI<br>' + b + '</p>' );
document.write( '<p>decodeURI<br>' + decodeURI( b ) + '</p>' );
document.write( '<p>encodeURIComponent<br>' + c + '</p>' );
document.write( '<p>decodeURIComponent<br>' + decodeURIComponent( c ) + '</p>' );
</script>
</body>
</html>
728x90
LIST