3 Answers, 1 is accepted
0
neven
Top achievements
Rank 1
answered on 30 Aug 2012, 11:57 AM
Hi,
Below is an working example how to write to file system (sd card). This doesn't cover fully your question but is a good starting point:
<!DOCTYPE html>
<html>
<head>
<title>FileWriter Example</title>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8">
// Wait for Cordova to load
//
document.addEventListener("deviceready", onDeviceReady, false);
// Cordova is ready
//
function onDeviceReady() {
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
}
function gotFS(fileSystem) {
console.log(fileSystem.root.fullPath);
fname="IceActionLog.txt";
console.log("Full Path Name is " + fname);
fileSystem.root.getFile(fname, {create: true, exclusive: false}, gotFileEntry, fail);
}
function gotFileEntry(fileEntry) {
fileEntry.createWriter(gotFileWriter, fail);
}
function gotFileWriter(writer) {
writer.write("This is written on onDevice ready.");
}
function fail(error) {
console.log(error.code);
}
</script>
</head>
<body>
Testing onDeviceReady - writning to the file system
</body>
</html>
Below is an working example how to write to file system (sd card). This doesn't cover fully your question but is a good starting point:
<!DOCTYPE html>
<html>
<head>
<title>FileWriter Example</title>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8">
// Wait for Cordova to load
//
document.addEventListener("deviceready", onDeviceReady, false);
// Cordova is ready
//
function onDeviceReady() {
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
}
function gotFS(fileSystem) {
console.log(fileSystem.root.fullPath);
fname="IceActionLog.txt";
console.log("Full Path Name is " + fname);
fileSystem.root.getFile(fname, {create: true, exclusive: false}, gotFileEntry, fail);
}
function gotFileEntry(fileEntry) {
fileEntry.createWriter(gotFileWriter, fail);
}
function gotFileWriter(writer) {
writer.write("This is written on onDevice ready.");
}
function fail(error) {
console.log(error.code);
}
</script>
</head>
<body>
Testing onDeviceReady - writning to the file system
</body>
</html>
0
Criulean
Top achievements
Rank 1
answered on 04 Sep 2012, 05:15 PM
Neven Thank you for your response but how to use this code for a button <a> ?
0