Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A callback for a page refresh function

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');
});
like image 547
Tommy Naidich Avatar asked Jun 04 '13 20:06

Tommy Naidich


1 Answers

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.

like image 156
xbonez Avatar answered Oct 03 '22 14:10

xbonez