Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

js open file dialog

var input = document.createElement('input');
input.style.visibility = 'hidden';
input.type = 'file';

input.onchange = e => { 

   // getting a hold of the file reference
   var file = e.target.files[0]; 

   // setting up the reader
   var reader = new FileReader();
   reader.readAsText(file,'UTF-8');

   // here we tell the reader what to do when it's done reading...
   reader.onload = readerEvent => {
      var content = readerEvent.target.result; // this is the content!
      console.log( content );
   }

}

input.click();
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #js #open #file #dialog
ADD COMMENT
Topic
Name
4+5 =