프로그램/Html_JavaScript

encodeURI() 와 encodeURIComponent() 의 차이점.

(주)CKBcorp., 2018. 2. 11. 13:26
반응형



백만년 만이구만.


작업하다가, 웹 선택값을 다음 페이지로 넘길 일이 생겼는데, 한글 문자열 값이었다.

그래서, encodeURI() 를 쓰려고 봤더니.... 이게 encodeURI()encodeURIComponent() 두가지가 있네?

두가지 차이점이 뭔지 몰라서 인터넷 뒤져보니 아래와 같다고 한다. 


https://stackoverflow.com/questions/14317861/difference-between-escape-encodeuri-encodeuricomponent


결론부터 이야기하면, encodeURIComponent() 써라. 

url 로 값 넘길때, get 방식으로 넘길 경우는 변수간 구별 delimiter 로 "&" 를 쓰는데, encodeURI() 는 앤드 기호를 UTF-8 로 변경해 주지 않는다.


물론 복호화 할 때는 당연히 decodeURI() / decodeURIComponent() 써야 된다. 처음부터 구별해서 쓰면 상관없는데, 나중에 수정하면 버그나기 딱 좋은 각.

 


반응형