最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

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

matteradmin6PV0评论

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.

Post a comment

comment list (0)

  1. No comments so far