防止Safari 5中的后退按钮缓存 [英] Preventing cache on back-button in Safari 5

查看:77
本文介绍了防止Safari 5中的后退按钮缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自最近发布的safari 5以来,事实证明这对我的网站造成了一些问题。我有一个动态网站,该网站运行经典的ASP(尽管应该无关紧要),并且该网站对历史记录堆栈有一些创造性的使用。例如,您可以在列出产品的页面上,然后转到有关产品的详细信息并更改产品(管理员视图)。当您单击产品上的保存时,信息将通过AJAX发送到服务器,并发出 history.back()。这在所有浏览器(包括safari< = 4)中都很好用,但是,在新发布的safari 5中,它停止了工作。看来,当您在野生动物园5中单击时,它实际上并未刷新页面,而只是从缓存中加载页面,这意味着不会显示在详细信息视图中所做的更改。我该如何在safari 5中进行这项工作?这是当前我必须关闭缓存的代码(包括在每个页面的顶部):

As of recent safari 5 was released, and it turns out to cause some problems for my website. I have a dynamic website running classic ASP (though that shouldn't matter much) and the site has some creative use of the history stack. For instance, you can be on a page that lists products, then go to details about a product and change the product (admin-view). When you click save on the product the information is sent to the server via AJAX, and a history.back() is issued. This works great in all browsers (including safari <= 4), however, in the newly released safari 5 it stopped working. It seems that when you click back in safari 5 it doesn't actually refresh the page, it only loads it from cache, which means that the changes made in the details view isn't shown. How can I go about to make this work in safari 5 as well? This is the current code I have to turn off caching (included at the top of every page):

Dim pStr
pStr = "private, no-cache, no-store, must-revalidate"
Response.AddHeader "pragma","no-cache"      '?
Response.AddHeader "cache-control", pStr    '?  Er ikke sikker på om disse 3 siste er nødvendige.
Response.AddHeader "cache-control", "post-check=0, pre-check=0"     '?  Er ikke sikker på om disse 3 siste er nødvendige.
Response.AddHeader "Expires", "Mon, 26 Jul 1997 05:00:00 GMT"       '?
Response.AddHeader "Last-Modified", Now()


推荐答案

空的 unload 处理程序将不再起作用。相反,您可以检查 onpageshow 事件的持久化属性。初始页面加载时将其设置为false。从bfcache加载页面时,将其设置为true。

The empty unload handler will not work anymore. Instead you can check the persisted property of the onpageshow event. It is set to false on initial page load. When page is loaded from bfcache it is set to true.

从bfcache加载页面时,Kludgish解决方案是强制重新加载。

Kludgish solution is to force a reload when page is loaded from bfcache.

window.onpageshow = function(event) {
    if (event.persisted) {
        window.location.reload() 
    }
};

如果您使用的是jQuery,请执行以下操作:

If you are using jQuery then do:

$(window).bind("pageshow", function(event) {
    if (event.originalEvent.persisted) {
        window.location.reload() 
    }
});

这篇关于防止Safari 5中的后退按钮缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆