JavaScript读取文件内容 [英] JavaScript read file contents

查看:81
本文介绍了JavaScript读取文件内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您有新文档的网址,如何使用不是您所在页面的javascript检索文档中的数据。

我要做的是创建一个页面它有一个用于提供本地文件名的文本字段和一个从提供的文档中检索单词的按钮。

how can you retrieve the data from a document with javascript that isn't the page you are on if you have the url of the new document.
what i am trying to do is create a page that has a text field for providing a local file name and a button that retrieves the words from the document provided.

谢谢。

推荐答案

HTML5有一个文件API,可以让你读取本地文件。它至少支持Firefox(我认为是3.6及更高版本)和Chrome。我不知道是否有其他浏览器支持它。如果你需要支持其他浏览器,你将不得不回到像Flash那样的东西,但我对此没有任何经验。

HTML5 has a File API that lets you read local files. It's supported in at least Firefox (3.6 and later, I think) and Chrome. I don't know if any other browsers support it yet or not. If you need to support other browsers, you'll have to fall back to something like Flash, but I don't have any experience with that.

不幸的是,默认情况下Chrome不允许本地文件访问其他本地文件(每个文件都被认为来自其自己的域)。您可以通过在启动Chrome时添加 - allow-file-access-from-files 标记来明确允许它。

Unfortunately, by default Chrome doesn't allow local files to access other local files (each file is considered to be from its own domain). You can explicitly allow it by adding the --allow-file-access-from-files flag when you launch Chrome.

以下是对File API的一个很好的介绍,其中包含几个示例: http:// www .html5rocks.com / en / tutorials / file / dndfiles /

Here's a good introduction to the File API with several examples: http://www.html5rocks.com/en/tutorials/file/dndfiles/.

这篇关于JavaScript读取文件内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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