티스토리 뷰

자바스크립트를  사용하여 현재 페이지를 새로고침하려고 할 때는 location 객체의 reload 메소드를 사용하면 된다


.

1
2
location.reload();
window.location.reload();



위의 표현식 둘다 실행된다. 그 이유는 location 객체가 window 객체에 속해있기 때문에 원칙적으로는 아래와 같이 

표현해 주는게 맞지만 window 객체 자체가 최상의 전역객체이기 때문에 보통은 생략에서 사용한다. 그렇기 때문에

위의 표현식도 맞는 표현식이다.


w3schools 에는 이렇게 표현해 주고 있다.


1
2
3
4
5
6
7
8
9
The reload() method is used to reload the current document.
The reload() method does the same as the reload button in your browser.
By default, the reload() method reloads the page from the cache, but you can force it to 
reload the page from the server by setting the forceGet parameter to true: location.reload(true).
 
reload() 메소드는 현재 문서를 새로고침할 때 사용한다.
reload() 메소드는 사용하고 있는 브라우저의 새로고침 버튼과 동일하게 동작한다.
reload() 메소드는 기본적으로 캐시를 사용해서 새로고침하는데 forceGet 파라미터 세팅(true)을 통해서 
서버로부터 페이지를 다시 받아올 수 있다. 예) location.reload(true);



위의 설명을 보면 default forceGet 값은 false로 세팅되어 있는 것을 알 수 있다.


참고사이트


댓글