admin管理员组文章数量:1323348
FileReader allows to read local file in Chrome.
function readMultipleFiles(evt) {
var files = evt.target.files;
if (files) {
for (var i = 0, f; f = files[i]; i++) {
var r = new FileReader();
r.onload = (function (f) {
return function (e) {
var contents = e.target.result;
document.getElementById("output").innerHTML = contents;
};
})(f);
r.readAsText(f);
}
} else {
alert("Failed to load files");
}
}
document.getElementById('fileinput').addEventListener('change', readMultipleFiles, false);
Run example on jsfiddle
But this example does not work in Internet Explorer 9.
Does IE9 support File API?
If yes - what should I do to have ability to read local files in IE9?
FileReader allows to read local file in Chrome.
function readMultipleFiles(evt) {
var files = evt.target.files;
if (files) {
for (var i = 0, f; f = files[i]; i++) {
var r = new FileReader();
r.onload = (function (f) {
return function (e) {
var contents = e.target.result;
document.getElementById("output").innerHTML = contents;
};
})(f);
r.readAsText(f);
}
} else {
alert("Failed to load files");
}
}
document.getElementById('fileinput').addEventListener('change', readMultipleFiles, false);
Run example on jsfiddle
But this example does not work in Internet Explorer 9.
Does IE9 support File API?
If yes - what should I do to have ability to read local files in IE9?
5 Answers
Reset to default 3You can use ActiveX' FileSystemObject.
var fso = new ActiveXObject("Scripting.FileSystemObject");
var a = fso.CreateTextFile("c:\\testfile.txt", true);
a.WriteLine("This is a test.");
a.Close();
If you make an hypertext application (.hta), you will be able to create the ActiveX object FileSystemObject
, which will let you access the local file system.
Generally no. Reading local files is a massive security violation.
Does IE9 support File API?
No, it doesn't.
If yes - what should I do to have ability to read local files in IE9?
Did you mean if no? If so then you could use an ActiveX or just inform the user that this feature of your website is not supported on his browser and allow him the possibility to upload the file to the server.
Seems that FileSystemObject
like a hidden monster..
var fso, file, fileName = '/file.txt', fileContents = '';
if (fileName) {
fso = new ActiveXObject('Scripting.FileSystemObject');
// don't worry about 'camelCase' typing, works both
if (fso.fileExists(fileName)) {
file = fso.openTextFile(fileName, 1);
fileContents = file.readAll();
// or loop over lines
// while (!file.atEndOfStream) {
// fileContents += file.readLine();
// }
file.close();
}
}
More info: https://msdn.microsoft./en-us/library/314cz14s(v=vs.85).aspx
本文标签: htmlIs it possible in javascript to read local files in IEStack Overflow
版权声明:本文标题:html - Is it possible in javascript to read local files in IE? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742132996a2422246.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论