正如标题所说:有没有办法使用jquery mobile在phonegap中下载多个文件?
例如点击一个链接,然后下载一个漏洞库?
您可以使用 Phone gap FILE API 文件传输对象来执行此操作
如果你想下载多个文件,那么你可以在循环中使用文件传输,或者如果下载文件是 zip 格式,那么文件传输和提取 zip 插件对你来说很容易
方法一>
示例文件传输代码:
配置 Zip 插件然后应用此代码
function download(remoteFile)
{
var localFileName = remoteFile.substring(remoteFile.lastIndexOf('/') + 1);
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fileSystem) {
fileSystem.root.getFile(localFileName, { create: true, exclusive: false }, function (fileEntry) {
var localPath = fileEntry.fullPath;
console.log("localPath1:" + localPath);
if (device.platform === "Android" && localPath.indexOf("file://") === 0) {
localPath = localPath.substring(7);
}
console.log("localPath2 save:" + localPath);
console.log("thid is localFileName :"+localFileName);
extractFile(localFileName); //No need for other formated file except zip file.
var ft = new FileTransfer();
ft.download(remoteFile,
localPath, function (entry) {
console.log("file path:" + entry.fullPath);
var linkopen = document.getElementById("openlink");
linkopen.style.display = "block";
linkopen.href = entry.fullPath;
var zippath = entry.fullPath;
console.log(zippath);
$("#btnExtract").show();
}, fail);
}, fail);
}, fail);
console.log("completed");
}
*这里写这个代码是为了考虑Zipfile。您需要更改代码。
方法二:删除
提取文件(本地文件名);
从代码