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: