最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

jquery mobile - How to access a file in local system using JavaScript? - Stack Overflow

programmeradmin2浏览0评论

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.

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.

Share Improve this question edited Apr 15, 2011 at 10:02 bluish 27.4k28 gold badges125 silver badges184 bronze badges asked Dec 28, 2010 at 12:46 Ka-rocksKa-rocks 7741 gold badge14 silver badges28 bronze badges 1
  • any way of doing this would be a security hole and even if you find one - it will be fixed – naugtur Commented Jan 3, 2011 at 11:51
Add a ment  | 

3 Answers 3

Reset to default 3

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./JavaScript/articles/file_access_with_JavaScript.htm http://www.webreference./js/column71/

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

You can't access the filesystem from pure web-based JavaScript alone, especially not in a cross-platform or cross-browser manner. But you can access the filesystem from ActiveX Controls on Internet Explorer, from Firefox extensions, and from Java applets, all of which you might be able to interact with using JavaScript. Of course you'll have to get the user to install the ActiveX, extension, or applet on the browser first.

There is no way to do this in Javascript. Access to local files is categorically denied for security reasons.

You can link to the file using a <a> element but even that is disabled in most browsers.

发布评论

评论列表(0)

  1. 暂无评论