我查看了某些选项来访问在浏览器中缓存的文件,但我找不到。我最终只是通过监听缓存事件来计算缓存的文件数。
以下是代码:
var cacheStatusValues = [];
cacheStatusValues[0] = 'uncached';
cacheStatusValues[1] = 'idle';
cacheStatusValues[2] = 'checking';
cacheStatusValues[3] = 'downloading';
cacheStatusValues[4] = 'updateready';
cacheStatusValues[5] = 'obsolete';
var cache = window.applicationCache;
cache.addEventListener('cached', logEvent, false);
cache.addEventListener('checking', logEvent, false);
cache.addEventListener('downloading', logEvent, false);
cache.addEventListener('error', logEvent, false);
cache.addEventListener('noupdate', logEvent, false);
cache.addEventListener('obsolete', logEvent, false);
cache.addEventListener('progress', logEvent, false);
cache.addEventListener('updateready', logEvent, false);
var count=0;
function logEvent(e) {
var online, status, type, message;
online = (navigator.onLine) ? 'yes' : 'no';
status = cacheStatusValues[cache.status];
type = e.type;
message = 'online: ' + online;
message+= ', event: ' + type;
message+= ', status: ' + status;
if (type == 'error' && navigator.onLine) {
message+= ' (prolly a syntax error in manifest)';
}
console.log(message);
if(type=='progress') {
count++;
}
if(type=='cached') {
//count-1 is bcoz the "progress" events starts from 0
alert("Count of files Cached: "+count-1);
//alert(cache.mozItems());
}
}
我找不到遍历缓存文件的方法。在网上搜索我得到的答案有点像这样, “没有直接的Javascript界面来检查浏览器缓存的内容。如果你能够探测用户文件系统的内容,那将是一个安全隐患。”http://www.codestyle.org/javascript/faq-Browser.shtml。
但我仍然想知道是否可以使用javascript,最好是iOS支持的任何其他语言。如果在此线程中发布解决方案,将会有很大帮助。提前谢谢。