location 객체
: 브라우저의 주소표시줄 입력에 관련된 객체
location.href = 'url' ; : 해당 url로 이동
- 히스토리 객체에 이동 정보를 저장함
- = 뒤로가기 가능
<button id="href">href 사용 이동 (네이버) </button>
<script>
document.getElementById('href').addEventListener('click',()=>{
location.href='https://www.naver.com/';
})
</script>
location.replace('url'); : 해당 url로 이동
- 히스토리 객체에 이동 정보를 저장하지 않음
- = 뒤로가기 불가능
<button id="replace">replace 사용 이동 (다음) </button>
<script>
document.getElementById('replace').addEventListener('click',function(){
location.replace('https://www.daum.net/');
})
</script>
location.assign('url'); : 해당 url로 이동
- 히스토리 객체에 이동 정보를 저장함
- = 뒤로가기 가능
<button id="assign">assign 사용 이동 (유튜브) </button>
<script>
//함수 + onclick 방법
function assign(){
location.assign('https://www.youtube.com/');
}
document.getElementById('assign').addEventListener('click',assign);
</script>
location.relode(); : 현재 페이지 새로고침
- onclick = ' window.location.reload() ' 로 바로 사용도 가능!
<button onclick="window.location.reload()">reload 사용 새로고침</button>
'HTML.CSS.JS > JS' 카테고리의 다른 글
[JS] history 객체 (0) | 2023.04.21 |
---|---|
[JS] DOM ( Document Object Model ) : 문서(html) 객체 모델 (0) | 2023.04.21 |
[JS] setInterval 정해진 시간주기로 지속적 함수 호출 (0) | 2023.04.21 |
[JS] setTimeout 정해진 시간후 함수 실행 (0) | 2023.04.21 |
[JS] day13_구구단 게임 (0) | 2023.04.20 |