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

别说谁变了你拦得住时间么 提交于 2019-12-23 12:09:27

问题


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) ?


回答1:


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));



回答2:


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.



来源:https://stackoverflow.com/questions/6833452/how-to-refresh-page-when-hitting-back-button-on-browser-ie-chrome-firefox-safar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!