Web/Front
[Javascript] window.location 객체
yj_oo_
2021. 7. 30. 16:17
예제 도메인) https://realyun99.tistory.com:8080/mange/newpost?type=post#yj
Properties
Property | Description | Example |
hash | 주소값에 붙어있는 anchor값 반환 | #yj |
host | URL의 도메인과 포트 반환 | realyun99.tistory.com:8080 |
hostname | URL의 도메인 반환 | realyun99.tistory.com |
href | URL 반환 | https://realyun99.tistory.com:8080 |
origin | 프로토콜 + URL의 도메인 + 포트 | https://realyun99.tistory.com:8080 |
pathname | URL 경로 반환 | /mange/newpost |
port | 서버포트 반환 | 8080 |
protocol | 프로토콜 반환 | http: |
search | URL에 붙은 매개변수 반환(물음표 뒤의 값) | ?type=post |
Methods
Method | Description |
assign(url) | 새로운 주소 이동 |
reload(forceget) | 현재 페이지 새로고침 |
replace(url) | 새로운 주소 이동(세션 히스토리 없이) |
예제
- 새 페이지로 이동하기
window.location.assign("http://www.naver.com"); //or
window.location = "http://www.naver.com";
- 현재 페이지 새로고침
window.location.reload(true);
- replace()를 사용해 새 페이지로 이동하기
function reloadPageWithHash() {
var initialPage = window.location.pathname;
window.location.replace('http://www.naver.com/#' + initialPage);
}