IE and local file reading

本小妞迷上赌 提交于 2019-12-28 06:13:30

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/6710432/ie-and-local-file-reading

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!