2014-07-25 38 views
1

我已經寫了下面的代碼在javascript:如何使用FileSystem API的window.requestFileSystem?

javascript代碼:

var fs=null; 

     function initFS() { 
      window.requestFileSystem =window.requestFileSystem || window.webkitRequestFileSystem; 
       window.requestFileSystem (window.TEMPORARY, 1024 * 1024, function (filesystem) { 
       fs = filesystem; 
      }, errorHandler); 
     } 

的html代碼:

<input type="button" id="button2" name="click" value="show" onclick="initFS();" /> 

但點擊在initFS function顯示按鈕,行後後window.requestFileSystem (window.TEMPORARY, 1024 * 1024, function (filesystem) {
它將錯誤顯示爲「未捕獲類型錯誤」。我的代碼中有任何錯誤嗎?

回答

0

無法定義的ErrorHandler

var fs=null; 


     function initFS() { 
      window.requestFileSystem =window.requestFileSystem || window.webkitRequestFileSystem; 
       window.requestFileSystem(window.TEMPORARY, 1024 * 1024, function (filesystem) { 
       fs = filesystem; 
       console.log(fs); 
      }, errorHandler); 
     } 
     function errorHandler(e) { 
      console.log(e); // it show everything that you want 
      } 
+0

@Shikha:你可以告訴控制檯打印 –

+0

控制檯打印「FileError已被棄用,請使用‘姓名’或‘消息’屬性DOMError,而不是‘代碼’。 – Shikha

+0

閱讀此答案http://stackoverflow.com/questions/24930403/writing-to-a-file-in-javascript-using-filesystem-api可能會幫助,而不是FileError使用名稱和消息屬性 –

相關問題