我想弄清楚如何用下载的文件替换或添加 Phonegap 的一些源文件。
<!DOCTYPE html>
<html>
<head>
<title></title>
<script type="text/javascript" charset="utf-8" src="cordova-2.3.0.js"></script>
<script type="text/javascript">
function onBodyLoad()
{
document.addEventListener("deviceready", onDeviceReady, false);
}
function downloadFile(){
window.requestFileSystem(
LocalFileSystem.PERSISTENT, 0,
function onFileSystemSuccess(fileSystem) {
fileSystem.root.getFile(
"dummy.html", {create: true, exclusive: false},
function gotFileEntry(fileEntry){
var sPath = fileEntry.fullPath.replace("dummy.html","");
var fileTransfer = new FileTransfer();
fileEntry.remove();
fileTransfer.download(
"https://dl.dropbox.com/u/xxxxx/index_2.html",
sPath + "index_aerosoft.html",
function(theFile) {
console.log("download complete: " + theFile.toURI());
showLink(theFile.toURI());
},
function(error) {
console.log("download error source " + error.source);
console.log("download error target " + error.target);
console.log("upload error code: " + error.code);
}
);
},
fail);
},
fail);
}
function showLink(url){
alert(url);
var divEl = document.getElementById("ready");
var aElem = document.createElement("a");
aElem.setAttribute("target", "_blank");
aElem.setAttribute("href", url);
aElem.appendChild(document.createTextNode("Ready! Click To Open."))
divEl.appendChild(aElem);
}
function fail(evt) {
console.log(evt.target.error.code);
}
function onDeviceReady()
{
downloadFile();
}
</script>
</head>
<body onload="onBodyLoad()">
<br />
<p>
DOWNLOADING FILE...<br />
<span id="ready"></span>
</p>
</body>
</html>
我可以下载和访问该文件,但我可以在某处将下载路径设置为 Phonegap 中的“www”文件夹吗?或者我如何找出文件的路径(所以我可以链接到该路径)
Xcode 控制台告诉我
file://localhost/var/mobile/Applications/1AE34410-C57E-4896-8616-042E386552E0/Documents/index_2.html
我可以以某种方式链接到那个吗?