Search code examples
javascriptjquery-mobilefilesystem-access

How to access a file in local system using JavaScript?


I'm using jQuery Mobile framework. I'm having a server which hosts a website. The user can connect to website through mobile browser and download files (.doc, .xls, .pdf etc.) from that website. I need to open the file which is saved in the user's mobile programmatically using JavaScript. I tried to open using location.href="file://sdcard/download/test.doc". But it didn't work. It showed permission denied. Is there any way to this? Please help. Thanks in advance.


Solution

  • For security reasons, browsers will block all access to your local file system. You would have to use other extensions to access those files--or download them to a local variable instead of the file system.

    If regular old JavaScript could access your filesystem bad people would be able to do really bad things with greater ease and efficiency. There are a couple of possibilities if you are not using a browser:

    http://www.c-point.com/JavaScript/articles/file_access_with_JavaScript.htm http://www.webreference.com/js/column71/

    Those articles are fairly platform specific, and do not leverage the best practices for security though. Caveat Emptor