检查浏览器是否禁用离线应用程序缓存 [英] Check if offline application cache disabled by browser

查看:208
本文介绍了检查浏览器是否禁用离线应用程序缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个使用ApplicationCache存储离线数据的应用程序。长话短说,对于没有启用离线数据的用户来说,这是默默无闻的,通常是因为他们已经关闭了历史记录,或者正在使用隐私浏览功能,所以我想抓住这一点,并给用户一个明确的错误。



它显示,通过检查缓存的状态可以检测到这个状态,这将返回0 UNCACHED 当没有缓存...但我不知道这是否意味着没有缓存,或没有缓存保证(因为应该有,有什么不对)。 官方定义不是很有用:

$ $ $ $ $ $ $ $ $ $ $ $ $ UNCACHED(数值0)
ApplicationCache对象的缓存主机没有与应用程序相关联
缓存在这个时候。

实际上,放弃 cache.status == 0 似乎至少在Firefox上正常工作。我做对了,还是有更好的办法?如果有人可以挖掘一个状态图,则可以获得额外的分数。



更新:如果用户从来没有去过,它也会返回0 / UNCACHED那个页面之前。加油!

解决方案

监听错误 C> applicationCache 。当这种情况发生时, applicationCache.status === applicationCache.UNCACHED 中的一个原因是缓存被禁用。给用户的消息可能会提示缓存已关闭。


So I've got an application that stores offline data using an ApplicationCache. Long story short, it's silently dying for users who don't have offline data enabled, most commonly because they've got history turned off or are using private browsing, and I'd like to catch this and give the user a clear error.

It appears that this can be detected by checking the cache's state, which will return 0 UNCACHED when there is no cache... but I'm not sure if that means that there is no cache yet, or that there's no cache guaranteed (and because there should be, something's wrong). The official definition is less than useful:

UNCACHED (numeric value 0)
The ApplicationCache object's cache host is not associated with an application
cache at this time.

In practice, though, aborting on cache.status==0 seems to work fine at least on Firefox. Am I doing it right, or is there a better way? Extra points if somebody can dig up a state diagram.

Update: Nope, it also returns 0/UNCACHED if the user has never been to that page before. Gar!

解决方案

Listen for the error event on applicationCache. When this fires and applicationCache.status===applicationCache.UNCACHED, one reason among many is that caching is disabled. The message to the user may suggest that caching is turned off.

这篇关于检查浏览器是否禁用离线应用程序缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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