简体   繁体   English

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

[英]Error Not allowed to load local resource in javaScript

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.我有一个列表,我使用 document.getElementById(list1).style.listStyleImage='url("file:///D:/proj1/pro%20project/images/plus_icon.png")'; " .这里我使用了一个在D盘的图标来设置为列表图标。 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.png What is the reason for this issue and can please anyone suggest a way to fix this problem?但是当我的 web 应用程序运行时,它在这一行显示错误为Not allowed to load local resource: file:///D:/proj1/pro%20project/images/plus_icon.png这个问题的原因是什么?可以请任何人提出解决此问题的方法吗? Thank you.谢谢你。

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。

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现在它正在工作,请检查它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM