У меня есть небольшой html-файл, который вызывает файл javascript, но когда я пытаюсь получить к нему доступ в браузере, я получаю следующую ошибку:
Доступ к сценарию в
'file:///C:/Users/jekob/Desktop/battleship/index.js' из источника
'null' заблокирован политикой CORS: только запросы между источниками
поддерживается для схем протоколов: http, data, chrome-extension, Edge,
https, chrome-untrusted.
Я гуглил это часами и обнаружил, что могу разместить свое приложение на сервере (например, node.js), а затем разрешить CORS. Однако мне не нужен сервер. Мне нужен простой HTML и JS-файл.
index.html:
battle-ship
index.js:
import {board} from './board_0.1.js';
console.log(board);
board.js:
class cell{
constructor(){
this.locationByLetter = null;
this.locationByNumb = [];
this.occupied = false;
this.clicked = false;
}
}
class shipDitel{
constructor(name,size){
this.name = name;
this.size = size;
this.location =[];
}
}
export const board = buildBoard();
const shipType = [["Destroyer",2/*size*/],["Submarine",3],["Cruiser",3,],
["Battleship",4,],["AircraftCarrier",5]];
var shipsArr=setShip();
var selectedShip = selectShip(shipsArr[4]);
var stateGame ={
setting:true,
gameIsStart:false
}
function buildBoard(){
..
};
function setShip(){ //setting to a ship his name and size .
...
};
function selectShip(ship){
...
}
function onSelectedCell(cell){
...
};
function checkTheZone(cell){
...
};
Подробнее здесь: https://stackoverflow.com/questions/638 ... cors-issue