Home > database >  local images not loading due to cors error
local images not loading due to cors error

Time:12-03

When i try to load local images into my web project, i am getting the error

Access to XMLHttpRequest at 'file:///E:/Code Stuff/History Creative Media Project/fonts/ARCADECLASSIC.TTF' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, chrome-untrusted, https.

im getting a cors error when requesting images that are in the same file path as the index.html file. the weird part is that when using live server on visual studio code, i don't get these cors errors and everything works fine.

also, all of the other js files in my project are loaded fine, using the <script> tag in index.html to load them

CodePudding user response:

If you try to access file from "file:///" you are doing a request in another domain, not "http://localhost". I suggest you to access a file from a standard url in http or https.

CodePudding user response:

You can try to run your server using --allow-file-access-from-files like this example

$ /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome  --allow-file-access-from-files index.html 
  • Related