jQuery를 사용하여 페이지 (또는 특정 div)를 한 번 (!) 새로 고침 / 다시로드하는 방법이 궁금합니다.
이상적으로 DOM structure
는 사용 가능 ( onload
이벤트 참조 ) 직후에 부정적인 영향 back button
이나 bookmark
기능에 영향을주지 않는 방식 입니다.
참고 : replace()
타사 제한으로 인해 허용되지 않습니다.
답변
좋아, 나는 당신이 요구하는 것을 얻은 것 같습니다. 이 시도
if(window.top==window) {
// You're not in a frame, so you reload the site.
window.setTimeout('location.reload()', 3000); //Reloads after three seconds
}
else {
//You're inside a frame, so you stop reloading.
}
한 번이면 그냥 해
$('#div-id').triggerevent(function(){
$('#div-id').html(newContent);
});
주기적으로
function updateDiv(){
//Get new content through Ajax
...
$('#div-id').html(newContent);
}
setInterval(updateDiv, 5000); // That's five seconds
따라서 5 초마다 div # div-id 콘텐츠가 새로 고쳐집니다. 전체 페이지를 새로 고치는 것보다 낫습니다.
답변
다시로드하려면 다음을 시도하십시오.
window.location.reload(true);
답변
window.location.href=window.location.href;
답변
이것을 사용하십시오 :
<script type="text/javascript">
$(document).ready(function(){
// Check if the current URL contains '#'
if(document.URL.indexOf("#")==-1)
{
// Set the URL to whatever it was plus "#".
url = document.URL+"#";
location = "#";
//Reload the page
location.reload(true);
}
});
</script>
if
조건 으로 인해 페이지는 한 번만 새로 고침됩니다.
답변
$('#div-id').click(function(){
location.reload();
});
이것은 올바른 구문입니다.
$('#div-id').html(newContent); //This doesnt work
답변
이것은 JavaScript 기본이기 때문에 jQuery 새로 고침 기능이 없습니다.
이 시도:
<body onload="if (location.href.indexOf('reload')==-1) location.replace(location.href+'?reload');">
답변
사용하다:
<html>
<head>
<title>Reload (Refresh) Page Using Jquery</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#reload').click(function() {
window.location.reload();
});
});
</script>
</head>
<body>
<button id="reload" >Reload (Refresh) Page Using</button>
</body>
</html>
