Notice
Recent Posts
Recent Comments
Link
«   2025/04   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30
Tags
more
Archives
Today
Total
관리 메뉴

blog

[JavsScript] URL으로부터 parameter 얻기 본문

Web/front-end

[JavsScript] URL으로부터 parameter 얻기

hjkongkong 2022. 3. 23. 20:12

[해당 페이지 URL 가져오기]

document.location.href

 

[URL parameter 값 가져오기]

location.search

[?age=60&office=london] 이런 형식으로 가져온다.

 

참고 : https://fellowtuts.com/jquery/getting-query-string-values-in-javascript/?a=a

 

예시

https://example:8090/current_page_url?age=60

window.location.hostname;   // example
window.location.href;       //  https://example:8090/current_page_url?age=60
window.location.host;       // example:8090
window.location.port;       // 8090
window.location.pathname;   // /current_page_url
window.location.search;     // ?age=60
window.location.protocol;   // https: