Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IE and local file reading

I've just watched the mozilla File API file reading as

new FileReader();

etc. and I must ask is there something like that for IE?

like image 558
user592704 Avatar asked Jul 15 '11 16:07

user592704


People also ask

Can browser read local file?

Web browsers (and JavaScript) can only access local files with user permission. To standardize the file access from the browser, the W3C published the HTML5 File API in 2014. It defines how to access and upload local files with file objects in web applications.

How do I open a local file in Internet Explorer?

Press ctrl + O to open html file.

How do I read a local text file in HTML?

Using my own existing file upload input html - copying the lines from var reader = new FileReader(); through reader. readAsBinaryString(..) - it reads the contents of my text file.


2 Answers

Yes, you can use ActiveX' FileSystemObject. However, an confirmation box is shown to the user everytime he runs the code. Some users might not trust you and could choose not to run the ActiveX control. Also, please note that some users also use non-IE browsers which don't support FileReader (Safari, older versions of Firefox and so on). By adding ActiveX, you still won't have 100% support for file-related APIs.

like image 114
duri Avatar answered Sep 22 '22 01:09

duri


Internet Explorer 10 also supports the FileReader:

var reader = new FileReader();
reader.onloadend = function(){
    // do something with this.result
}
reader.readAsText(readFile);

For managed compatability tables regarding the FileReader, be sure to check out caniuse.com.

If you wanted to provide a fall-back for those who may not be visiting your site in Internet Explorer 10, I would encourage you to do a bit of feature-detection to determine whether or not you want to use the FileReader:

if ( window.FileReader ) {
    /* Use the FileReader */
} else {
    /* Do something else */ 
}

Note also that using an ActiveXObject approach isn't necessarily going to work all the time either as some users browse with ActiveX Filtering enabled, meaning you can't touch their file-system, or run any types of plugins in their browser.

like image 37
Sampson Avatar answered Sep 22 '22 01:09

Sampson