Pet*_*ete 80 jquery refresh reload
我想知道如何使用jQuery刷新/重新加载页面(甚至特定div)一次(!)?
理想情况下,在DOM structure可用之后(参见onload事件),并且不会产生负面影响back button或bookmark功能.
请注意:replace() 由于第三方限制,不允许:
Ben*_*Ben 79
好吧,我想我得到了你所要求的.试试这个
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.
}
Run Code Online (Sandbox Code Playgroud)
如果它是一次,那就做
$('#div-id').triggerevent(function(){
$('#div-id').html(newContent);
});
Run Code Online (Sandbox Code Playgroud)
如果是定期的
function updateDiv(){
//Get new content through Ajax
...
$('#div-id').html(newContent);
}
setInterval(updateDiv, 5000); // That's five seconds
Run Code Online (Sandbox Code Playgroud)
因此,div#div-id内容每五秒钟刷新一次.比刷新整个页面更好.
Mil*_*lli 66
要重新加载,您可以尝试这样做:
window.location.reload(true);
Run Code Online (Sandbox Code Playgroud)
Maz*_*Maz 40
window.location.href=window.location.href;
Run Code Online (Sandbox Code Playgroud)
小智 5
用这个:
<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>
Run Code Online (Sandbox Code Playgroud)
由于这种if情况,页面只会重新加载一次。