JavaScript를 사용하여 페이지를 새로고침하는 방법

JavaScript를 사용하여 페이지를 새로고침하려면 어떻게 해야 합니까?

모든 브라우저에서 사용할 수 있는 방법이 필요합니다.



질문에 대한 답변



자바 스크립트 1.2,

window.location.reload(); // If we needed to force the document to be fetched from the // web server again (such as where the document contents // change dynamically but cache control headers are not // configured properly), Firefox supports a non-standard // parameter that can be set to true to bypass the cache: //window.location.reload(true); 

자바 스크립트 1.1

window.location.replace(window.location.pathname + window.location.search + window.location.hash); // does not create a history entry 

자바 스크립트 1.0

window.location.href = window.location.pathname + window.location.search + window.location.hash; // creates a history entry 



location.reload(); 

자세한 내용은 이 MDN 페이지를 참조하십시오.

재충전하고 나서onclick그 후 바로 거짓으로 반환해야 합니다.

location.reload(); return false; 



POST 요구로 취득한 페이지의 새로고침에 관한 정보를 찾고 있었습니다.예를 들어, POST 요구를 송신한 후 등입니다.method="post"형태.

POST 데이터를 보관 유지하는 페이지를 새로고침하려면 다음 명령을 사용합니다.

window.location.reload(); 

POST 데이터를 폐기하는 페이지를 새로고침하려면(GET 요청을 수행합니다) 다음과 같이 사용합니다.

window.location.href = window.location.href; 

이것이 다른 사람들이 같은 정보를 찾는 데 도움이 되기를 바랍니다.




이 작업은 다음을 사용하여 수행할 수 있습니다.window.location.reload();여러 가지 방법이 있지만 자바스크립트로 같은 문서를 새로고침 하는 것이 적절하다고 생각합니다.여기 설명이 있습니다.

자바스크립트window.location오브젝트를 사용할 수 있습니다.

  • 현재 페이지 주소(URL)를 가져오려면
  • 브라우저를 다른 페이지로 리디렉션하다
  • 같은 페이지를 새로 고치다

window: in JavaScript는 브라우저의 열린 창을 나타냅니다.

location: in JavaScript에는 현재 URL에 대한 정보가 저장됩니다.

location오브젝트는 의 단편과 같습니다.window를 통해 호출됩니다.window.location소유물.

locationobject에는 다음 세 가지 메서드가 있습니다.

  1. assign(): 새 문서를 로드하는 데 사용됩니다.
  2. reload(): 현재 문서를 새로고침하기 위해 사용합니다.
  3. replace(): 현재 문서를 새 문서로 바꾸기 위해 사용합니다.

그래서 우리는 여기서reload()같은 문서를 새로고침하는 데 도움이 되기 때문입니다.

그래서 이렇게 쓰세요.window.location.reload();.

jsfiddle 온라인 데모

브라우저에서 캐시에서가 아닌 서버에서 직접 페이지를 가져오도록 요청하려면true에 대한 파라미터location.reload()이 방법은 IE, Chrome, Firefox, Safari, Opera 등 모든 주요 브라우저와 호환됩니다.




시험:

window.location.reload(true); 

true로 설정된 파라미터는 서버에서 새로운 복사본을 새로고침합니다.생략하면 캐시에서 페이지가 제공됩니다.

자세한 내용은 MSDNMozilla 문서를 참조하십시오.