1

i want to give the file location url for the code to get my file instead of using input file in html part , to pass the file to the code

the code pasted below works if i use " input type= "file" " to get the file, but if i use url (like below) it gives a error

fileInput1.addEventListener is not a function
at window.onload 

here is the code

window.onload = function() {
var z ="C:/Users/akash/Desktop/riidl/UTham.txt"
    var fileInput1 = z;
if (fileInput1){
    fileInput1.addEventListener('change', function(e) {
        var file = fileInput1.files[0];
        var textType = /text.*/;

        if (file.type.match(textType)) {
            var reader = new FileReader();
            reader.onload = function(e) {
                spamdata=reader.result;
                document.getElementById('here').onclick = console.log(spamdata);

              }    
            reader.readAsText(file);                    
        } 
    });
}

}

1 Answers1

0

Accessing local files is not allowed in JavaScript for security purposes.

Pl refer to this answer for more details.

https://stackoverflow.com/a/372333/3626796

Dinesh Pandiyan
  • 5,814
  • 2
  • 30
  • 49