Javascript-форум (https://javascript.ru/forum/)
-   Общие вопросы Javascript (https://javascript.ru/forum/misc/)
-   -   CORS ошибка,при открытии index.html (https://javascript.ru/forum/misc/80549-cors-oshibka-pri-otkrytii-index-html.html)

ab3 19.06.2020 08:42

CORS ошибка,при открытии index.html
 
Если открывать через "Live Server" в VSCode то все работает,а если открывать просто index.html ,то в консоли выдает ошибку

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.



:help:

SuperZen 19.06.2020 09:37

подключение скрипта gallery.js из html файла в студию :)

ab3 19.06.2020 09:47

<!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>

voraa 19.06.2020 10:36

Модули нельзя использовать при локальном вызове
Только по протоколам http https

ab3 19.06.2020 10:56

Тогда у меня импорты не работают

Uncaught SyntaxError: Cannot use import statement outside a modul

import gallery from "./gallery-items.js";

SuperZen 19.06.2020 11:49

тогда нужен https://webpack.js.org/guides/getting-started/ или https://parceljs.org/getting_started.html или https://chrome.google.com/webstore/d...nigeejlf?hl=en

ab3 22.06.2020 09:43

Спасибо


Часовой пояс GMT +3, время: 21:40.