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
Post a Comment