Is it possible to access file with extension *.txt or *.file in JavaScript? I want to call this file in my function?
Asked
Active
Viewed 4,449 times
2
-
Javascript in a browser? And a local file? By call do you mean execute? – Robert Dec 08 '10 at 08:18
-
From server or client computer ? – Dec 08 '10 at 08:18
-
@Rober: how do you execute a `.txt` or `.file` ? – Dec 08 '10 at 08:19
-
Like the other guys said, it's not possible to do this in the browser. Can you explain why you want to do this is more detail? Maybe we can find a different solution for you. – Jakob Dec 08 '10 at 08:19
-
You can with a work-around: I'd suggest searching Stack Overflow, though, as this is a common question: http://stackoverflow.com/questions/1981815/jquery-read-a-text-file http://stackoverflow.com/questions/196498/how-do-i-load-the-contents-of-a-text-file-into-a-javascript-variable – peirix Dec 08 '10 at 08:20
-
@ robert : yes, i mean execute – user495688 Dec 08 '10 at 08:50
-
@jacob : i want to store some word for example is,am,are,the,a,an in file then i will execute it in function – user495688 Dec 08 '10 at 08:53
3 Answers
6
If you are talking about javascript running in a web browser then the answer is no, you cannot access files on the client computer unless you use some proprietary technology like Silverlight, ActiveX, Flash, ...
If you want to access files stored on the server then you could use AJAX to query a server side script which would return the contents of the file.

Darin Dimitrov
- 1,023,142
- 271
- 3,287
- 2,928
1
You will not be able to read the file contents using javascript which is executed in a browser. Since javascript runs in a client browser reading a file from the file system will be a secirity threat.

rahul
- 184,426
- 49
- 232
- 263
0
As of HTML5 there are new features for file access, see https://stackoverflow.com/a/7056216/356726

Community
- 1
- 1

Horst Walter
- 13,663
- 32
- 126
- 228