Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to refresh page when hitting back button on browser (IE,Chrome,Firefox Safari)?

Most browsers reload the page from cache and do not perform a round trip server refresh. I added Response.AppendHeader("Cache-Control", "no-store") on Page_Load but not working for Chrome, Firefox, Safari. How to refresh page when hitting back button on browser (IE,Chrome,Firefox Safari) ?

like image 742
arlen Avatar asked Jul 26 '11 16:07

arlen


2 Answers

This would be for your c# code I'm assuming. These are my suggestions in order of most suggested to least.

Response.Cache.SetNoStore();

Response.Cache.SetCacheability(HttpCacheability.NoCache);

Response.AppendHeader("pragma","no-cache");

Response.Cache.SetExpires(DateTime.Now.AddSeconds(-1));
like image 192
abney317 Avatar answered Oct 09 '22 10:10

abney317


It's probably a bad idea to force this behavior because the user is expecting to see what they saw before, not a refreshed view. If that's the behavior of Chrome/Firefox/Safari then presumably the users desire this behavior because they chose that browser. If they want a refreshed view, they can refresh on their own.

That said, I often see this done with Javascript in the browser. You can hook into page load events and manually refresh if you see the page being loaded a second time. But if the client uses noscript, or otherwise doesn't support Javascript, then you're out of luck. Also, be careful to reload correctly so that users don't get taken to a new page every time they click Back and get stuck in a battle of fast-clicking reflexes.

like image 2
Rag Avatar answered Oct 09 '22 10:10

Rag