tags:

views:

86

answers:

5

I tried to open file with

window.open("file:///D:/Hello.txt");

The browser does not allow opening of local file this way, probably for security reasons. I want to use the file's data in the client side. How can I read local file in javascript?

+2  A: 

Maybe you could try using flash if you want to handle client side data :

An example : http://www.adylevy.com/index.php/2009/06/07/client-side-image-resize-flash-cs4-filereferencedata/

markcial
+1 there is no other way than this. The browsers don't allow doing it using JS.
Pekka
Well... actually, you could get the urldata with some scripting, this article give some hints about that : http://css-tricks.com/local-previews-of-images/
markcial
+1  A: 

It is not possible. Either you use a web server where file can be uploaded and than use its content or write an extension for browser.

Adeel
+1  A: 

You can't. new browsers like firefox, safari etc. block 'file' protocole. it will only work on old browsers.

you'll have to upload files you want.

youssef azari
+1  A: 

There is no standard way in Javascript to manipulate local files, like you said it's for security reason. You can use ActiveX on IE and XPCOM on Mozilla though. Here is a link discussing the XPCOM way.

teukkam
+1  A: 

The HTML5 fileReader facility ( http://dev.w3.org/2006/webapi/FileAPI/ ) does allow you to process local files, but these MUST be selected by the user, you cannot go rooting about the users disk looking for files.

I currently use this with development versions of Chrome (6.x). I don't know what other browsers support it.

Hans B PUFAL