HTML 4相当于HTML 5的FileReader? [英] HTML 4 equivalent of HTML 5's FileReader?

查看:135
本文介绍了HTML 4相当于HTML 5的FileReader?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网页,需要能够从运行浏览器的本地机器加载文件到DOM。我发现这是很容易做到使用HTML 5 File API。

I've got a web page which needs to be able to load files into the DOM from the local machine on which the browser is running. I've found that this is very easy to do using the HTML 5 File API.

我可以这样做:

var reader = new FileReader();  
reader.onload = function (fileContents) { ... load contents to a div ... }
reader.readAsText(f) //where f is an HTML5 File object

令人遗憾的是,我需要这个工作在IE7,还有一些早期版本的Firefox不支持API。

Annoyingly, I need this to work in IE7, and also some earlier versions of Firefox which don't support the API. Is there any easy way to load a local file into the DOM in older browsers?

非常感谢!

推荐答案

除此之外的其他答案,似乎没有一致的方式做这个客户端(除了Flash)旧版本的浏览器。

Further to the other answers here, it does appear that there's no consistent way of doing this client-side (other than Flash) for older browsers.

然而,对于IE7 / 8,我已经设法使用ActiveX来一起攻击。

For IE7/8 however, I've managed to hack something together using ActiveX.

var filePath = f:\oo.txt;
var fso = new ActiveXObject("Scripting.FileSystemObject");
var textStream = fso.OpenTextFile(filePath);
var fileData = file.ReadAll();

然后,我可以将此传递给上面问题中的reader.onload函数。显然这是一个坏的,黑客的解决方案,并可能被一些安全政策阻止 - 它至少工作在IE7虽然!

I can then pass this to the same function as reader.onload in the question above. Obviously this is a bad, hacky solution, and liable to be blocked by some security policies - it does at least work for IE7 though!

这篇关于HTML 4相当于HTML 5的FileReader?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆