Is there any way to implement a callback for a page refresh function, check if the page is ready after it is refreshed and then print a message? I'd like to show refresh the page and show a certain message after clicking a button, however, I need to stay within my code in order to know what message to show. Anything similar to the next code would be great:
location.reload(function(){
alert ('done refreshing and document is ready');
});
On page reload, your JS application gets re-initialized and starts all over again, so you cannot have a callback.
However, what you can do is add a hash fragment to the URL before reloading.
window.location = window.location.href + "#refresh";
window.location.reload();
Then, on page load, check if the hash fragment exists. If it does, you'll know you just refreshed the 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