Catalina
Catalina

Reputation: 2098

JavaScript read file contents

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.

thanks.

Upvotes: 2

Views: 4827

Answers (2)

Matthew Crumley
Matthew Crumley

Reputation: 102725

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.

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.

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

Upvotes: 4

Diodeus - James MacFarlane
Diodeus - James MacFarlane

Reputation: 114367

Browser security does not allow direct access to the local filesystem. If it could, web pages would be able to steal any file of your machine.

HTML5 local storage does allow local access, but on a different principle.

Upvotes: 1

Related Questions