以下是当前API的两个示例。
它使用navigator.webkitPersistentStorage.requestQuota而不是不推荐使用的window.webkitStorageInfo.queryUsageAndQuota:
查询配额
navigator.webkitTemporaryStorage.queryUsageAndQuota (
function(usedBytes, grantedBytes) {
console.log('we are using ', usedBytes, ' of ', grantedBytes, 'bytes');
},
function(e) { console.log('Error', e); }
);
请求配额
var requestedBytes = 1024*1024*280;
navigator.webkitPersistentStorage.requestQuota (
requestedBytes, function(grantedBytes) {
console.log('we were granted ', grantedBytes, 'bytes');
}, function(e) { console.log('Error', e); }
);
您必须选择临时(webkitTemporaryStorage)或持久性(webkitPersistentStorage)存储来进行查询。
chromestore.js为此数据提供了更简单的API。
要回答您的原始问题,您的新代码将如下所示:
请求配额并初始化文件系统
var requestedBytes = 1024*1024*280;
navigator.webkitPersistentStorage.requestQuota (
requestedBytes, function(grantedBytes) {
window.webkitRequestFileSystem(PERSISTENT, grantedBytes, onInitFs, errorHandler);
}, function(e) { console.log('Error', e); }
);