javascript - How to get file location as variable in NWJS -


i trying file location variable in nw.js. have code nw.js docs can not figure out how use return file location. need write script use id “filedialog” result? https://github.com/nwjs/nw.js/wiki/file-dialogs

**html** <input style="display:none;" id="filedialog" type="file" />  **javascript** <script>   function choosefile(name) {     var chooser = document.queryselector(name);     chooser.addeventlistener("change", function(evt) {       console.log(this.value);     }, false);      chooser.click();     }   choosefile('#filedialog'); </script> 

you better access file name via file list input.files:

https://github.com/nwjs/nw.js/wiki/file-dialogs lile list section.

the called function async callback wont able return names calling function. handle files in callback.

function choosefile(name, handlefile) {     var chooser = document.queryselector(name);     chooser.addeventlistener("change", function(evt) {         for(var f of this.files){             console.log(f.name);             console.log(f.path);             handlefile(f.name, f.path);         }     }, false);      chooser.click();   } choosefile('#filedialog', function(name, path){ ... /* file(s) */ }); 

Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -