본문 바로가기

Vanilla JS

[자바스크립트] 현재 페이지 URL가져오기

window.location.href

현재 페이지의 URL을 가져옵니다

//https://www.naver.com

window.location.href
//=>https://www.naver.com

window.location.pathname

hostname 뒤의 '/'문자 뒤의 경로를 가져옵니다.

//https://svelte.dev/examples/svg-transitions

window.location.pathname
//=>'/examples/svg-transitions'

 

 

window.location.search

'?' 뒤의 쿼리스트링을 가져옵니다.

//.com/manage/newpost/?type=post

window.location.search
//=> '?type=post'