I'm wondering how to refresh/reload a page (or even specific div) once(!) using jQuery?
Ideally in a way right after the DOM structure
is available (cf. onload
event) and not negatively affecting back button
or bookmark
functionality.
Please, note: replace()
is not allowed due to third-party restrictions.
hash property & without changing/adding hash(#) sign to the URL of the page. We are going to use DOM location reload() method to achieve the same.
Method 1: Using the location. reload(): The location. reload() method reloads the current web page emulating the clicking of the refresh button on the browser.
Using location. reload() Method: This method is used to reload the current page imitating the action of the refresh button of the browser.
You can use the location. reload() JavaScript method to reload the current URL. This method functions similarly to the browser's Refresh button. The reload() method is the main method responsible for page reloading.
Alright, I think I got what you're asking for. Try this
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. }
If it is once, then just do
$('#div-id').triggerevent(function(){ $('#div-id').html(newContent); });
If it is periodically
function updateDiv(){ //Get new content through Ajax ... $('#div-id').html(newContent); } setInterval(updateDiv, 5000); // That's five seconds
So, every five seconds the div #div-id content will refresh. Better than refreshing the whole page.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With