I’d like to fire some code whenever a page is shown in the browser:
$(function() {
console.log('got ready event!');
});
This event gets fired only when the browser downloads the page. If I navigate to a different page, then go back, the above snippet won’t be fired. It seems that the browser caches the page state, because the server does not receive any requests when the page is shown.
So when I go back to the page, it restores the cached page state without firing the ready event.
Is there an event I can listen to whenever the page is shown, regardless of whether the page is cached or not?
The directive
cashe-control:no-casheindicates cached information should not be used and instead requests should be forwarded to the origin server.Try the
pageshowevent: