Error “Not allowed to load local resource: file://

2019-02-09 12:53发布

问题:

This question already has an answer here:

  • How can I create a link to a local file on a locally-run web page? 5 answers

The below code is not working when running on server(nodejs) in chrome

<span><a href="file://sharedpath" target="_blank">Open folder.</a></span>

I am getting the following error message in the developer tool:

Not allowed to load local resource: file://sharedpath

But when opening the same path(file://sharedpath) in the browser(new tab), I am able to see the folder structure of that path. The same is working fine in IE. Is this a problem with Chrome? Or is this a problem when running on the server? Can anyone suggest something on this issue?

回答1:

Make sure that your host is fully qualified: Source

Try adding an additional slash: file:///sharedpath

See this answer

Specifically:

Some browsers, like modern versions of Chrome, will even refuse to cross from the http protocol to the file protocol, so you'd better make sure you open this locally using the file protocol if you want to do this stuff at all.



回答2:

Not sure what your whole context here is, but I used the web server extension for chrome for something similar when testing a local-build of something I'd eventually deploy (but wasn't ready to yet), and it worked great.

Just go to the extension url: https://chrome.google.com/webstore/detail/web-server-for-chrome/ofhbbkphhbklhfoeikjpcbhemlocgigb

Add the extension, enable it, and point it to the folder that contains the local file that you're having trouble with, and it should work correctly.

Hope that helps!