单击后退按钮时,防止从缓存加载safari [英] Prevent safari loading from cache when back button is clicked

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

问题描述

单击后退按钮时,遇到装有旧YouTube视频的safari时遇到问题。我已经尝试添加onunload =(这里提到防止后台缓存 - Safari 5中的按钮)到body标签,但在这种情况下它不起作用。

Got an issue with safari loading old youtube videos when back button is clicked. I have tried adding onunload="" (mentioned here Preventing cache on back-button in Safari 5) to the body tag but it doesn't work in this case.

有没有办法阻止从缓存中加载safari某个页面?

Is there any way to prevent safari loading from cache on a certain page?

推荐答案

您的问题是由后退缓存。当用户导航时,它应该保存完整的页面状态。当用户使用后退按钮页面导航时,可以非常快速地从缓存加载。这与只缓存HTML代码的普通缓存不同。

Your problem is caused by back-forward cache. It is supposed to save complete state of page when user navigates away. When user navigates back with back button page can be loaded from cache very quickly. This is different from normal cache which only caches HTML code.

当为bfcache加载页面 onload 事件不会是触发。相反,您可以检查 onpageshow 事件的持久属性。初始页面加载时设置为false。从bfcache加载页面时,它设置为true。

When page is loaded for bfcache onload event wont be triggered. 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.

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

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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