5 초마다 페이지를 다시로드하는 방법?
하나의 레이아웃을 html로 변환하고 있습니다. F5를 칠 때마다 code / html / css를 변경하면 이것에 대한 간단한 자바 스크립트 / jQuery 솔루션이 있습니까? 즉, 스크립트를 추가 한 후 5 초마다 (또는 다른 특정 시간마다) 전체 페이지를 다시로드하십시오.
<meta http-equiv="refresh" content="5; URL=http://www.yourdomain.com/yoursite.html">
스크립트에 있어야하는 경우 다음 과 같이 setTimeout을 사용하십시오 .
setTimeout(function(){
window.location.reload(1);
}, 5000);
동일한 페이지를 다시로드하려면 두 번째 인수가 필요하지 않습니다. 당신은 단지 사용할 수 있습니다 :
<meta http-equiv="refresh" content="30" />
30 초마다 다시로드를 트리거합니다.
3 초 후 자동 재로드 및 캐시 지우기를 위해 javascript setInterval 함수를 사용하여 쉽게 수행 할 수 있습니다. 간단한 코드는 다음과 같습니다
$(document).ready(function() {
setInterval(function() {
cache_clear()
}, 3000);
});
function cache_clear() {
window.location.reload(true);
// window.location.reload(); use this if you do not remove cache
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<p>Auto reload page and clear cache</p>
그리고 이것을 위해 메타를 사용할 수도 있습니다
<meta http-equiv="Refresh" content="5">
setTimeout(function () { location.reload(1); }, 5000);
그러나 개발 도구가 진행되면 https://addons.mozilla.org/en-US/firefox/addon/115를 사용하는 것이 좋습니다.
IE를위한 자동 변경시 새로 고침 도구가 있습니다. 이름은 ReloadIt이며 http://reloadit.codeplex.com 에서 사용할 수 있습니다 . 비어 있는.
자동 새로 고침 할 URL을 선택하고 하나 이상의 디렉토리 경로를 지정하여 변경 사항을 모니터링합니다. F12를 눌러 모니터링을 시작하십시오.
설정 한 후 최소화하십시오. 그런 다음 컨텐츠 파일을 편집하십시오. 변경 사항을 저장하면 페이지가 다시로드됩니다. 이처럼 :
단순한. 쉬운.
@jAndy가 제공 한 답변은 작동하지만 Firefox 에서는 문제가 발생할 수 있습니다. window.location.reload (1) ; 작동하지 않을 수 있습니다, 그것은 나의 개인적인 경험입니다.
그래서 제안하고 싶습니다 :
setTimeout(function() { window.location=window.location;},5000);
이것은 테스트되고 잘 작동합니다.
A decent alternative if you're using firefox is the XRefresh plugin. It will reload your page everytime it detect the file has been modified. So rather than just refreshing every 5 seconds, it will just refresh when you hit save in your HTML editor.
Alternatively there's the application called LiveReload...
If you are developing and testing in Firefox, there's a plug-in called "ReloadEvery" is available, which allows you to reload the page at the specified intervals.
This will work on 5 sec.
5000 milliseconds = 5 seconds
Use this with target _self
or what ever you want and what ever page you want including itself:
<script type="text/javascript">
function load()
{
setTimeout("window.open('http://YourPage.com', '_self');", 5000);
}
</script>
<body onload="load()">
Or this with automatic self and no target code with what ever page you want, including itself:
<script type="text/javascript">
function load()
{
setTimeout("location.href = 'http://YourPage.com';", 5000);
}
</script>
<body onload="load()">
또는 자체 페이지를 다시로드하고 원하는 견인 모자를 대상으로하는 동일한 페이지 인 경우 :
<script type="text/javascript">
function load()
{
setTimeout("window.open(self.location, '_self');", 5000);
}
</script>
<body onload="load()">
세 가지 모두 다른 방식으로 비슷한 일을합니다.
function reload() {
document.location.reload();
}
setTimeout(reload, 5000);
참고 URL : https://stackoverflow.com/questions/2787679/how-to-reload-page-every-5-seconds
'development' 카테고리의 다른 글
IntelliJ에서 코드 글꼴 크기를 늘리는 방법은 무엇입니까? (0) | 2020.05.26 |
---|---|
저장하는 동안 iphone Core Data Unresolved 오류 (0) | 2020.05.26 |
셀레늄 C # 웹 드라이버 : 요소가 나타날 때까지 기다립니다 (0) | 2020.05.26 |
Java "이 언어 레벨에서 지원되지 않는 람다 표현식" (0) | 2020.05.26 |
JavaScript를 사용하여 'div'표시 / 숨기기 (0) | 2020.05.26 |