如何在浏览器(IE,Chrome,Firefox Safari)上按回按钮时刷新页面?

时间:2022-11-24 09:03:54

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

大多数浏览器从缓存重新加载页面,不执行往返服务器刷新。我在Page_Load上添加了Response.AppendHeader(“Cache-Control”,“no-store”),但不适用于Chrome,Firefox,Safari。如何在浏览器(IE,Chrome,Firefox Safari)上按回按钮时刷新页面?

2 个解决方案

#1


5  

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

这将是我假设的c#代码。根据大多数人的建议,这些是我的建议。

Response.Cache.SetNoStore();

Response.Cache.SetCacheability(HttpCacheability.NoCache);

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

Response.Cache.SetExpires(DateTime.Now.AddSeconds(-1));

#2


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.

强制执行此行为可能是一个坏主意,因为用户希望看到之前看到的内容,而不是刷新的视图。如果这是Chrome / Firefox / Safari的行为,那么大概是用户希望这种行为,因为他们选择了该浏览器。如果他们想要刷新视图,他们可以自己刷新。

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.

也就是说,我经常在浏览器中看到这是用Javascript完成的。如果您第二次看到正在加载的页面,则可以挂钩页面加载事件并手动刷新。但是如果客户端使用noscript,或者不支持Javascript,那么你运气不好。此外,请注意正确重新加载,以便用户每次单击“返回”时都不会被带到新页面并陷入快速点击反应之中。

#1


5  

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

这将是我假设的c#代码。根据大多数人的建议,这些是我的建议。

Response.Cache.SetNoStore();

Response.Cache.SetCacheability(HttpCacheability.NoCache);

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

Response.Cache.SetExpires(DateTime.Now.AddSeconds(-1));

#2


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.

强制执行此行为可能是一个坏主意,因为用户希望看到之前看到的内容,而不是刷新的视图。如果这是Chrome / Firefox / Safari的行为,那么大概是用户希望这种行为,因为他们选择了该浏览器。如果他们想要刷新视图,他们可以自己刷新。

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.

也就是说,我经常在浏览器中看到这是用Javascript完成的。如果您第二次看到正在加载的页面,则可以挂钩页面加载事件并手动刷新。但是如果客户端使用noscript,或者不支持Javascript,那么你运气不好。此外,请注意正确重新加载,以便用户每次单击“返回”时都不会被带到新页面并陷入快速点击反应之中。