iconfu / svg-inject

A tiny, intuitive, robust, caching solution for injecting SVG files inline into the DOM.
MIT License
800 stars 85 forks source link

Access to XMLHttpRequest has been blocked by CORS policy #53

Open minglaitin opened 3 years ago

minglaitin commented 3 years ago

I was trying to load a local SVG file into my html but it was not successful

<head>
  <script src="svg-inject.js"></script>
</head>
<body>
  <img src="earth.svg" onload="SVGInject(this)">
</body>

I opened the console and found the following warning

SQLInject_issue

How can I deal with this issue?

xmyhoang commented 3 years ago

You should consider using a local web server to let your browser render local files in http. I used the command python3 -m http.server in the terminal to open my file and now it works.

Consult this stack overflow post for more details and other solutions beside using python: https://stackoverflow.com/questions/10752055/cross-origin-requests-are-only-supported-for-http-error-when-loading-a-local