window.requestFileSystem()函数的简单示例

我有下一个问题:我尝试在Chrome中使用window.requestFileSystem()函数,但它失败了。 寻找我的步骤:

1)我在Chrome中添加了“允许从文件访问文件”标志(请参阅img bellow): 在此处输入图像描述

2)我重新启动了系统。

3)然后我用’允许文件访问文件’标志运行Chrome。

4)毕竟我尝试启动此示例代码:

 function onInitFs(fs) { console.log('Opened file system: ' + fs.name); } function errorHandler(e) { console.log("Error"); } window.requestFileSystem(window.TEMPORARY, 5*1024*1024 /*5MB*/, onInitFs, errorHandler); 

但它失败了: 在此处输入图像描述

我的行为有什么问题?

那是因为此function目前只能使用前缀,即window.webkitRequestFileSystem

你可能会发现这个有趣的东西: http ://www.html5rocks.com/en/tutorials/file/filesystem/

此代码适用于chrome。 我实际上将它用于手机屏幕,但我先在笔记本上用chrome测试它,并在浏览器顶部出现一个黄色条,要求我允许网络应用程序永久存储在我的本地驱动器上。

  navigator.webkitPersistentStorage.requestQuota(1024*1024, function(grantedBytes) { window.requestFileSystem(window.PERSISTENT, grantedBytes, onInitFs, errorHandler); }, function(errorCode) { alert("Storage not granted."); } ); 

使用以下命令从命令行打开chrome

 chrome --allow-file-access-from-files 

你应该改变

 window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem; 

 window.RequestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem; 

(R应该已经大写了。)