M
M
Mykhailo Nikolaiev2020-06-21 23:47:01
JavaScript
Mykhailo Nikolaiev, 2020-06-21 23:47:01

CORS, how to open a file on GitHub?

If you open via "Live Server" in VSCode, then everything works, but if you open just index.html, then it gives an error in the console. How to use modules so as not to receive CORS?

Access to script at 'file:///D:/js/gallery.js' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension , https.

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
    <link rel="stylesheet" href="/css/style.css" />
  </head>
  <body>
    <ul class="gallery js-gallery"></ul>

    <div class="lightbox js-lightbox">
      <div class="lightbox__overlay"></div>

      <div class="lightbox__content">
        <img class="lightbox__image" src="" alt="" />
      </div>

      <button
        type="button"
        class="lightbox__button"
        data-action="close-lightbox"
      ></button>
    </div>
    <script src="/js/gallery.js" type="module"></script>
  </body>
</html>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Kovalsky, 2020-06-22
@lazalu68

If you just need to disable CORS for development, then you can download the extension for this, in my chrome, for example, it costs "Allow CORS: Access-Control-Allow-Origin"

A
Aetae, 2020-06-21
@Aetae

No way. At least without interfering with the giblets of the browser using some extension thread.
Run a local server or pack into a regular script with some build system.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question