Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reload page once using JQuery?

Tags:

jquery

How can I reload a page once on page load (an equivalent to pressing F5)

$( window ).load(function() {   
    window.location.reload(true); 
});

This loops itself. How can I make it happen only once?

like image 425
Matoeil Avatar asked Nov 14 '13 15:11

Matoeil


People also ask

How do you refresh a page every 5 seconds?

setTimeout(function () { location. reload(1); }, 5000);

How can I tell if jQuery is refreshing a page?

On Refresh/Reload/F5: If user will refresh the page, first window. onbeforeunload will fire with IsRefresh value = "Close" and then window. onload will fire with IsRefresh value = "Load", so now you can determine at last that your page is refreshing.

How do you refresh a page in JavaScript?

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.


1 Answers

This will do it:

if (window.location.href.indexOf('reload')==-1) {
     window.location.replace(window.location.href+'?reload');
}

With your jQuery-Code:

$( window ).load(function() {
    if (window.location.href.indexOf('reload')==-1) {
         window.location.replace(window.location.href+'?reload');
    }
});
like image 141
Reeno Avatar answered Oct 28 '22 12:10

Reeno