错误不允许在 javaScript 中加载本地资源

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33981775/
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-10-28 17:05:34  来源:igfitidea点击:

Error Not allowed to load local resource in javaScript

javascripthtmlcsshtml-lists

提问by Desi Delite

This may be very simple question. I had a list and I customized its icon by using "document.getElementById(list1).style.listStyleImage='url("file:///D:/proj1/pro%20project/images/plus_icon.png")';".Here I used a icon which is in D drive to set as list icon. I checked this url and it nicely show the icon in web brawser. But when my web application was run , It shows an error in this line as Not allowed to load local resource: file:///D:/proj1/pro%20project/images/plus_icon.pngWhat is the reason for this issue and can please anyone suggest a way to fix this problem? Thank you.

这可能是一个非常简单的问题。我有一个列表,我使用document.getElementById(list1).style.listStyleImage='url("file:///D:/proj1/pro%20project/images/plus_icon.png")';自定义了它的图标。这里我使用了一个位于 D 驱动器中的图标来设置为列表图标。我检查了这个网址,它很好地显示了网络浏览器中的图标。但是当我的 web 应用程序运行时,它在这一行显示错误为Not allowed to load local resource: file:///D:/proj1/pro%20project/images/plus_icon.png这个问题的原因是什么?可以请任何人提出解决此问题的方法吗?谢谢你。

回答by Haych

I found this link which has a similar problem: https://webmasters.stackexchange.com/questions/53870/cannot-load-local-resource

我发现这个链接有类似的问题:https: //webmasters.stackexchange.com/questions/53870/cannot-load-local-resource

It basically says that because you are using a local path to a file in your webpage, you're stating that the file exists locally to the client and not on your server. The way that it says to fix it is you should store the file in a directory that's served by your web server, and then use a URL to the file that includes your hostname.

它基本上是说,因为您使用的是网页中文件的本地路径,所以您声明该文件存在于客户端本地而不是您的服务器上。它所说的修复方法是您应该将文件存储在由您的 Web 服务器提供服务的目录中,然后使用包含您的主机名的文件的 URL。

回答by Dinesh

Don't use the full path,

不要使用完整路径,

Please find the below url for this url("../images/plus_icon.png")

请找到此网址的以下网址(“../images/plus_icon.png”)

Now it is work please check it

现在它正在工作,请检查它