Javascript 不使用输入按钮读取文件

Javascript 不使用输入按钮读取文件,javascript,cordova,dojo,Javascript,Cordova,Dojo,我们正在讨论的文件是zip类型的 <input type="file" id="file-input" name="files[]" accept="application/zip"/> 意味着点击按钮获得查找器/资源管理器。选择zip文件,然后在更改列表中获得文件的实例 console.log显示 File success tpk-layer1.html:168 File {webkitRelativePath: "", lastModifiedDate: Tue Se

我们正在讨论的文件是zip类型的

    <input type="file" id="file-input" name="files[]" accept="application/zip"/>
意味着点击按钮获得查找器/资源管理器。选择zip文件,然后在更改列表中获得文件的实例

console.log显示

File success 
tpk-layer1.html:168 File {webkitRelativePath: "", lastModifiedDate: Tue Sep 09 2014 11:50:18 GMT+0530 (IST), name: "Beirut.zip", type: "application/zip", size: 14263592…}lastModifiedDate: Tue Sep 09 2014 11:50:18 GMT+0530 (IST)name: "Beirut.zip"size: 14263592type: "application/zip"webkitRelativePath: ""__proto__: File 
我不想要按钮实例。也就是说,这个onclick和listner需要删除,应该在页面加载时直接调用文件

我如何才能做到这一点。如果需要任何澄清,请让我知道

更多信息

我试过打电话

zipParser('/samples/tpks/Beirut.zip');
但得到的回应是

Uncaught TypeError: Failed to execute 'readAsArrayBuffer' on 'FileReader': The argument is not a Blob. 

请注意,这是针对Phonegap应用程序的

如果它是您需要的blob,您可以使用XMLHttpRequest:

var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function(){
    if (this.readyState == 4 && this.status == 200){
       var blob = this.response;
       // Call zipParser?
       zipParser(blob);
    }
}
xhr.open('GET', './yourZipFile.zip');
xhr.responseType = 'blob';
xhr.send();   

你怎么知道在页面加载时加载哪个文件呢?它是一个zip文件,我随身携带的一个文件。可以包含在源代码中,最后一点是一个相当大的编辑。我已经添加了phonegap作为标签,因为如果您想从设备中提取文件,AJAX将不起作用。@LithuT.V没问题,在黑暗中大刀阔斧就可以了!
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function(){
    if (this.readyState == 4 && this.status == 200){
       var blob = this.response;
       // Call zipParser?
       zipParser(blob);
    }
}
xhr.open('GET', './yourZipFile.zip');
xhr.responseType = 'blob';
xhr.send();