user592704
user592704

Reputation: 3704

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?

Upvotes: 6

Views: 24289

Answers (2)

Sampson
Sampson

Reputation: 268354

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.

Upvotes: 8

duri
duri

Reputation: 15351

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.

Upvotes: 8

Related Questions