Ich frage mich, wie ich eine Seite (oder sogar ein bestimmtes Div) einmal (!) Mit jQuery aktualisieren/neu laden kann.
Idealerweise direkt nachdem das Ereignis DOM structure
Verfügbar ist (vgl. onload
) und die Funktionalität von back button
Oder bookmark
nicht beeinträchtigt.
Bitte beachten Sie: replace()
ist aufgrund von Einschränkungen durch Dritte nicht zulässig.
Okay, ich glaube, ich habe das bekommen, wonach du fragst. Versuche dies
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.
}
Wenn es einmal ist, dann tu es einfach
$('#div-id').triggerevent(function(){
$('#div-id').html(newContent);
});
Wenn es in regelmäßigen Abständen ist
function updateDiv(){
//Get new content through Ajax
...
$('#div-id').html(newContent);
}
setInterval(updateDiv, 5000); // That's five seconds
Alle fünf Sekunden wird der div # div-id-Inhalt aktualisiert. Besser als die ganze Seite zu aktualisieren.
Zum erneuten Laden können Sie Folgendes versuchen:
window.location.reload(true);
window.location.href=window.location.href;
Benutze das:
<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>
Aufgrund der Bedingung if
wird die Seite nur einmal neu geladen.
$('#div-id').click(function(){
location.reload();
});
Dies ist die korrekte Syntax.
$('#div-id').html(newContent); //This doesnt work
Sie haben keine jQuery-Aktualisierungsfunktion, da dies JavaScript-Grundlagen sind.
Versuche dies:
<body onload="if (location.href.indexOf('reload')==-1) location.replace(location.href+'?reload');">
Verwenden:
<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>
- 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']
Sie brauchen dafür kein jQuery. Sie können es mit JavaScript tun.
Fügen Sie dies oben in Ihre Datei ein, und die Site wird alle 30 Sekunden aktualisiert.
<script type="text/javascript">
window.onload = Refresh;
function Refresh() {
setTimeout("refreshPage();", 30000);
}
function refreshPage() {
window.location = location.href;
}
</script>
Eine andere ist: Fügen Sie die Kopfmarke hinzu
<meta http-equiv="refresh" content="30">
Verwenden Sie dies stattdessen
function timedRefresh(timeoutPeriod) {
setTimeout("location.reload(true);",timeoutPeriod);
}
<a href="javascript:timedRefresh(2000)">image</a>
Versuchen Sie diesen Code:
$('#iframe').attr('src', $('#iframe').attr('src'));
Versuche dies:
<input type="button" value="Reload" onClick="history.go(0)">
Möglicherweise müssen Sie this
reference zusammen mit location.reload()
verwenden. Aktivieren Sie dies, es wird funktionieren.
this.location.reload();
Zum Aktualisieren der Seite mit Javascript können Sie einfach Folgendes verwenden:
location.reload();