I need to somehow detect that the user has pressed a browsers back button and reload the page with refresh (reloading the content and CSS) using jquery.
How to detect such action via jquery?
Because right now some elements are not reloaded if I use the back button in a browser. But if I use links in the website everything is refreshed and showed correctly.
IMPORTANT!
Some people have probably misunderstood what I want. I don't want to refresh the current page. I want to refresh the page that is loaded after I press the back button. here is what I mean in a more detailed way:
- user is visiting page1.
- while on page1 - he clicks on a link to page2.
- he is redirected to the page2
- now (Important part!) he clicks on the back button in browser because he wants to go back to page1
- he is back on the page1 - and now the page1 is being reloaded and something is alerted like "You are back!"
Just use jquery :
The above will work 100% when back or forward button has been clicked using ajax as well.
if it doesn't, there must be a misconfiguration in a different part of the script.
For example it might not reload if something like one of the example in the previous post is used
window.history.pushState('', null, './');
so when you do use
history.pushState();
make sure you use it properly.Suggestion in most cases you will just need:
No window.history... and make sure url is defined.
Hope that helps..
I found the best answer and it is working perfectly for me
just use this simple script in your link
or the button click event
when you use this, you refresh your page first and then go to next page, when you return back it will be having the last refreshed state.
I have used it in a CAS login and gives me what I want. Hope it helps .......
An alternative that solved the problem to me is to disable cache for the page. That make the browser to get the page from the server instead of using a cached version: