728x90
반응형
현재 페이지의 URL을 가져오기위해 window.location 을 사용하자!
// 'https://210one2.tistory.com/374'
window.location.href
// 'https:'
window.location.protocol
// '210one2.tistory.com'
window.location.host
// '210one2.tistory.com'
window.location.hostname
// ''
window.location.port
// '/374'
window.location.pathname
// ?category=14157"
window.location.search
window.location.href
전체 url 문자열을 가져온다.
window.location.protocol
마지막 : 를 포함한 프로토콜 정보를 가져온다.
window.location.host
URL 의 호스트 정보를 가져온다.
window.location.hostname
URL의 호스트명을 가져온다.
이 값은 : 과 포트번호를 포함하지 않는다.
window.location.port
URL의 포트번호
window.location.pathname
hostname 뒤의 / 문자 경로를 가져온다.
window.location..search
쿼리스트링을 가져온다.
출처
https://hianna.tistory.com/464
[Javascript] 현재 페이지 URL 가져오기
Javascript에서 현재 페이지의 URL 주소를 가져오는 방법을 소개합니다. window.location (Location 객체) 현재 페이지의 URL을 알아오기 위해 window.location 속성을 사용할 수 있습니다. window.location 속성..
hianna.tistory.com
728x90
반응형
'Language > Java Script' 카테고리의 다른 글
| Element.closest() (0) | 2022.02.24 |
|---|---|
| 국가 코드 (0) | 2022.02.23 |
| .empty() (0) | 2022.02.08 |
| spring message properties 2탄 (0) | 2022.01.11 |
| var, let, const 차이점 (0) | 2022.01.03 |
| 현재 메뉴를 하이라이트 처리하기 (0) | 2022.01.03 |