我想弄清楚如何用下載的文件替換或添加一些Phonegap的源文件。Phonegap下載html文件並將其替換(來源)
<!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>
我可以下載和訪問該文件,但我可以在某處設置下載到'www'文件夾在Phonegap中的路徑嗎? 或如何找出該文件的路徑(這樣我就可以鏈接到該路徑)
Xcode的控制檯告訴我 file://localhost/var/mobile/Applications/1AE34410-C57E-4896-8616-042E386552E0/Documents/index_2.html
我可以以某種方式鏈接到?
您無法覆蓋應用程序中捆綁的文件。您只能寫入永久存儲上的位置。 – codemonkey