how to access file in javascript? [duplicate]
Is it possible to access file with extension 开发者_运维知识库*.txt or *.file in JavaScript? I want to call this file in my function?
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.
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.
As of HTML5 there are new features for file access, see https://stackoverflow.com/a/7056216/356726
精彩评论