-1

Is there a way I can open a file in my local computer using javascript whether it is a jpg, doc, or pdf?

I tried all the codes I found in the internet and I got an "Access Denied" or "Permission Denied" error when running it. I think it is also a security issue.

2 Answers2

1

Well, you've answered your own question: it is a security issue. Browser implementations of JS sort-of sandboxes JS. You can interact with the browser, you can request the browser to do certain things (like JS has access to the DOM via an API in browser implementations), but you can't just go ahead and do things.
Not only because of security limitations, but also in part because JS, left to its own devices, has no IO capabilities.

So, basically: JS lacks IO capabilities, and browsers don't provide an IO API that allows scripts to access the client's local file-system. And thank Christ for that, if such an API would have been available, browsing the web would be as risky a thing to do as... trying to teach lions to read in a nuclear reactor, while covered in hot-sauce or something...

Elias Van Ootegem
  • 74,482
  • 9
  • 111
  • 149
0

major browsers block these kind of requests to access local files because of security reasons.

Super Hornet
  • 2,839
  • 5
  • 27
  • 55