Javascript window.requestFileSystem 不工作

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6803064/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 23:15:36  来源:igfitidea点击:

window.requestFileSystem not working

javascripthtmlhtml5-filesystem

提问by Tony2

I am trying on Firefox,IE 9,Chrome and Opera the code below ,but the onInitFs(fs) function doesn't get called.if I add '()' to onInitFs in the window.requestFileSystem(window.PERSISTENT, 1024*1024, onInitFs, errorHandler) that function get called but fs is null ? Does anybody know how to solve this problem?I try on windows 7.I'll appreciate very much your help.

我正在 Firefox、IE 9、Chrome 和 Opera 上尝试下面的代码,但是没有调用 onInitFs(fs) 函数。如果我在 window.requestFileSystem(window.PERSISTENT, 1024*) 中将 '()' 添加到 onInitFs 1024, onInitFs, errorHandler) 该函数被调用但 fs 为空?有人知道如何解决这个问题吗?我在 Windows 7 上试过。非常感谢您的帮助。

<!DOCTYPE HTML>
`<html>
    <head>  
    <script>
        function errorHandler(e){
            alert("errorrrr");
        }
        function onInitFs(fs){
        alert("onInitFs");
        }
        function readClick(){
                 if (window.webkitRequestFileSystem) {
                     window.webkitRequestFileSystem(window.PERSISTENT, 1024*1024,onInitFs,errorHandler);
                } 
                 else {
                    window.requestFileSystem(window.PERSISTENT, 1024*1024, onInitFs, errorHandler);
                }

            alert("read finishsssss");
        }
        </script>
    </head>
<body>
<input type="button" value="Read dir" onclick="readClick()">
    <ul id="filelist"></ul>
</body>
</html>

回答by Raynos

Only chrome supports requestFileSystemas the webkitRequestFileSystemversion.

仅支持 chromerequestFileSystem作为webkitRequestFileSystem版本。

None of the other browsers (FF6, IE9, Op11) support this

其他浏览器(FF6、IE9、Op11)都不支持这个

回答by Marvin Emil Brach

Disregarding the security issue that you cannot "browse" local files with a website, your question should be answered:

不考虑您无法通过网站“浏览”本地文件的安全问题,您的问题应该得到回答:

When requesting a PERSISTENT filesystem you have to request a quota in first. Try that instead:

请求持久性文件系统时,您必须首先请求配额。试试这个:

window.storageInfo.requestQuota(PERSISTENT, 1024*1024, 
    function(grantedBytes) {
        window.requestFileSystem(window.PERSISTENT, grantedBytes, onInitFs, errorHandler);
    }, 
    errorHandler
);