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?
setTimeout(function () { location. reload(1); }, 5000);
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.
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.
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');
}
});
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