escape() | 적절한 정도로 인코딩한다. |
unescape() | 적절한 정도로 디코딩한다. |
encodeURI(uri) | 최소한의 문자만 인코딩한다 |
decodeURI(encodedURI) | 최소한의 문자만 디코딩한다. |
encodeURIComponent(uriComponent) | 대부분의 문자를 인코딩한다. |
decodeURIComponent(encodedURI) | 대부분의 문자를 디코딩한다. |
escape()
- 영문 알파벳, 숫자, 일부 특수문자(@, *, -, _, +, ., /)를 제외한 모든 문자를 인코딩한다.
- 1바이트 문자는 %XX의 형태로, 2바이트 문자는 %uXXXX의 형태로 변환한다.
- +를 인코딩하지 않으므로 약간의 문제가 발생할 수 있다.
encodeURI()
- escape() 함수에서 인터넷 주소에 사용되는 일부 특수문자(:, ;, /, ?, &)는 변환하지 않는다.
encodeURIComponent()
- 알파벳과 숫자를 제외한 모든 문자를 인코딩한다.
- UTF-8 인코딩과 같다.
- 가장 많이 사용하는 함수
<script>
var URI = 'http://www.javascript.com?test=한글';
var output = '';
output += '원문\n';
output += URI + '\n\n';
output += 'escape\n';
output += escape(URI) + '\n\n';
output += 'encodeURI\n';
output += encodeURI(URI) + '\n\n';
output += 'encodeURIComponent\n';
output += encodeURIComponent(URI) + '\n\n';
alert(output );
</script>
'JavaScript' 카테고리의 다른 글
alert, confirm, prompt (0) | 2014.02.13 |
---|
댓글