[英]selecting a file using location url instead of input file in html5 filereader for javascript
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 我想提供代码的文件位置网址,以获取我的文件,而不是在html部分中使用输入文件,以将文件传递给代码
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 如果我使用“ input type =“ file”“来获取文件,则下面粘贴的代码将起作用,但是如果我使用url(如下所示),则会出现错误
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);
}
});
}
} }
Accessing local files is not allowed in JavaScript for security purposes. 为了安全起见,JavaScript中不允许访问本地文件。
Pl refer to this answer for more details. 请参阅此答案以获取更多详细信息。
https://stackoverflow.com/a/372333/3626796 https://stackoverflow.com/a/372333/3626796
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.