我想知道如何使用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
因此,div#div-id内容每五秒钟刷新一次。比刷新整个页面更好。
请改用它
function timedRefresh(timeoutPeriod) {
setTimeout("location.reload(true);",timeoutPeriod);
}
<a href="javascript:timedRefresh(2000)">image</a>
试试这段代码:
$('#iframe').attr('src', $('#iframe').attr('src'));
试试这个:
<input type="button" value="Reload" onClick="history.go(0)">
要使用javascript刷新页面,您只需使用:
location.reload();
你可能需要使用this
参考和location.reload()
检查这一点,它会工作。
this.location.reload();
要重新加载,您可以尝试这样做:
window.location.reload(true);
window.location.href=window.location.href;
$('#div-id').click(function(){
location.reload();
});
这是正确的语法。
$('#div-id').html(newContent); //This doesnt work
用这个:
<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
条件,页面将只重新加载一次。
您没有jQuery刷新功能,因为这是JavaScript基础知识。
试试这个:
<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>
将其添加到文件的顶部,该网站将每30秒刷新一次。
<script type="text/javascript">
window.onload = Refresh;
function Refresh() {
setTimeout("refreshPage();", 30000);
}
function refreshPage() {
window.location = location.href;
}
</script>
另一个是:添加头标签
<meta http-equiv="refresh" content="30">
- location = location
- location = location.href
- location = window.location
- location = self.location
- location = window.location.href
- location = self.location.href
- location = location['href']
- location = window['location']
- location = window['location'].href
- location = window['location']['href']
你不需要jQuery。你可以用JavaScript做到这一点。