javascript - how to set dynamic value (textbox value) to cordova download plugin -
i new cordova plugin , in thing.. have implemented coedova plugin download file.. cordova plugin
here code..
var app = { filename: "abc.txt", //<-- 1 want dynamic uristring: "http://.....", //<-- 1 want dynamic // application constructor initialize: function() { this.bindevents(); }, downloadfile: function(uristring, targetfile) { var lblprogress = document.getelementbyid('lblprogress'); var complete = function() { lblprogress.innerhtml = 'done'; }; var error = function (err) { console.log('error: ' + err); lblprogress.innerhtml = 'error: ' + err; }; var progress = function(progress) { lblprogress.innerhtml = (100 * progress.bytesreceived / progress.totalbytestoreceive) + '%'; }; try{ var downloader = new backgroundtransfer.backgrounddownloader(); // create new download operation. var download = downloader.createdownload(uristring, targetfile); // start download , persist promise able cancel download. app.downloadpromise = download.startasync().then(complete, error, progress); } catch(err) { console.log('error: ' + err); } }, // bind event listeners // // bind events required on startup. common events are: // 'load', 'deviceready', 'offline', , 'online'. bindevents: function() { document.addeventlistener('deviceready', this.ondeviceready, false); document.getelementbyid('btnstart').addeventlistener('click', this.startdownload); document.getelementbyid('btnstop').addeventlistener('click', this.stopdownload); document.getelementbyid('btnfileinfo').addeventlistener('click', this.getfileinfo); }, // deviceready event handler // // scope of 'this' event. in order call 'receivedevent' // function, must explicity call 'app.receivedevent(...);' ondeviceready: function() { app.receivedevent('deviceready'); app.startdownload(); }, startdownload: function () { window.requestfilesystem(localfilesystem.persistent, 0, function(filesystem) { filesystem.root.getfile(app.filename, { create: true }, function (newfile) { app.downloadfile(app.uristring, newfile); }); }); }, stopdownload: function () { app.downloadpromise && app.downloadpromise.cancel(); }, getfileinfo: function () { window.requestfilesystem(localfilesystem.persistent, 0, function (filesystem) { filesystem.root.getfile(app.filename, { create: true }, function (fileentry) { fileentry.file(function (meta) { document.getelementbyid('lblfileinfo').innerhtml = "modified: " + meta.lastmodifieddate + "<br/>" + "size: " + meta.size; }); }, function(error) { document.getelementbyid('lblfileinfo').innerhtml = "error: " + error; }); }); }, // update dom on received event receivedevent: function(id) { var parentelement = document.getelementbyid(id); var listeningelement = parentelement.queryselector('.listening'); var receivedelement = parentelement.queryselector('.received'); listeningelement.setattribute('style', 'display:none;'); receivedelement.setattribute('style', 'display:block;'); console.log('received event: ' + id); }
};
this js file start downloading when page load or click on start button.. want remove onpage load , set when button click.. how set dynamic value of uristring , filename??.....
Comments
Post a Comment