0

I have a folder in D:\testDownload .I want to open the folder on click of a button. How to place the code inside the javascript function.

function open(){

}

user1400915
  • 1,933
  • 6
  • 29
  • 55
  • 4
    That's not possible, *unless* your page is also local. – Rob W Jun 29 '12 at 15:31
  • Take a look at this post: http://stackoverflow.com/questions/3582671/how-to-open-local-disk-file-with-javascript – Maresh Jun 29 '12 at 15:34
  • @RobW And for Chrome you need to start it with `--allow-file-access-from-files` when working locally for AJAX and such – TheZ Jun 29 '12 at 15:34

2 Answers2

0

If you want to simply browse to the location you can just use window.location = 'd:\\testDownload'. Most browsers will allow you to browse local discs. This is just the equivalent of typing that URL in the address bar.

But this will only work for your specific case on your local machine. It is not possible to do anything like this in the context of the web. For starters, you don't know where peoples' download locations are, you can't guarantee that they allow file browsing (what about mobile browsers etc).

If you want to open an Explorer window, then you're out of luck.

EDIT: Travis Pessetto is wrong. This works, served from the local disk.

<html>
<body>
<script type="text/javascript">
    function test() {
        window.location = "/tmp/"
    }
</script>
<a onclick="test()">click me</a>
</body>
</html>
Joe
  • 46,419
  • 33
  • 155
  • 245
  • Security settings in browsers do not allow a website to open these kind of links even if you can browse the filesystem with them. – Travis Pessetto Jun 29 '12 at 18:08
  • you are probably using an old browser or running on localhost (127.0.0.1) Running from [this jsFiddle](http://jsfiddle.net/plowdawg/v9mz9/1/) Firebug outputs "access denied" in the console. So you're right when it comes to the localhost but my guess is that it isn't going to be ran on just that one machine. A network, maybe. – Travis Pessetto Jun 29 '12 at 18:48
  • I'm using Chrome latest, but running off local disk (as I said in my answer), not localhost. – Joe Jun 30 '12 at 17:07
0

It isn't possible due to security reasons as seen on this question Open local folder from link. You may be able to do it using a Java applet, but not with JavaScript.

It would also be not that grate of a solution as Mac and Linux do not use drive-letters and it is possible Windows users don't use the same drive letter.

Community
  • 1
  • 1
Travis Pessetto
  • 3,260
  • 4
  • 27
  • 55