Javascript 错误“不允许加载本地资源:file://sharedpath”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32509068/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 10:32:10  来源:igfitidea点击:

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

javascriptangularjsnode.jsgoogle-chromeinternet-explorer

提问by Anudeep Kota

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

在 chrome 中的服务器(nodejs)上运行时,以下代码不起作用

<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

不允许加载本地资源: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?

但是当file://sharedpath在浏览器(新选项卡)中打开相同的路径()时,我能够看到该路径的文件夹结构。同样在 IE 中工作正常。这是 Chrome 的问题吗?或者这是在服务器上运行时的问题?任何人都可以就这个问题提出建议吗?

回答by Justin

Make sure that your host is fully qualified: Source

确保您的主机完全合格: 来源

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

尝试添加一个额外的斜线: 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.

一些浏览器,比如现代版本的 Chrome,甚至会拒绝从 http 协议到文件协议,所以如果你想要做这些事情,最好确保使用文件协议在本地打开它。

回答by sophistikaty

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.

不确定这里的整个上下文是什么,但是在测试我最终部署(但还没有准备好)的东西的本地构建时,我使用了 chrome 的 web 服务器扩展来做类似的事情,而且效果很好。

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

只需转到扩展网址: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!

希望有帮助!