Check if offline application cache disabled by browser

我只是一个虾纸丫 提交于 2019-12-11 09:56:36

问题


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!


回答1:


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.



来源:https://stackoverflow.com/questions/13281382/check-if-offline-application-cache-disabled-by-browser

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