devlog_zz

encodeURI() , encodeURIComponent() 본문

기록

encodeURI() , encodeURIComponent()

YJ_SW 2021. 1. 20. 09:59
728x90

URL로 사용할 수 없는 문자(한글, 특수문자, 예약어 )들을 사용할 수 있도록 인코딩 해주는 것

 

API 호출 시 URL로 사용할 수 없는 문자가 포함된다면encodeURI() / encodeURIComponent()

이와 같이 호출 해야함

 

encodeURI()

url 전체 인코딩 할 때

encodeURI("http://www.tistory.com/a t e s t.html")

encodeURI("http://www.tistory.com/a t e s t.html")

결과

http://www.tistory.com/a%20t%20e%20s%20t.html

 

encodeURIComponent()

url 매개변수의 값을 인코딩 할 때

var p1 = encodeURIComponent("a test.html")
var url = "http://www.tistory.com/"+p1+"&param2=11";

결과

http://www.tistory.com/a%20test.html&param2=11
728x90

'기록' 카테고리의 다른 글

[GIT] git diff - 브랜치 별 파일 내용 비교 후 변경된 부분 적용하기  (0) 2022.09.13
IE promise 오류  (0) 2022.05.10
한글 byte, 영어 byte  (0) 2022.01.31
크롬 디버거  (0) 2020.12.04
Comments