英文:
Cannot call an external file when running JavaScript in Firefox
问题
我尝试在我的 index.html
中运行这个:
<script>
var stockfish = new Worker('./js/stockfish.js');
stockfish.addEventListener('message', function (e) {
console.log(e.data);
});
stockfish.postMessage('uci');
</script>
但是我收到以下错误消息:
安全错误:位于 file:///D:/ChessComparator/index.html 的内容无法从 file:///D:/ChessComparator/js/stockfish.js 加载数据
。
我无法在Chrome上运行Web Workers,也想不到其他浏览器来测试这个。
英文:
I'm trying to run this in my index.html
:
<script>
var stockfish = new Worker('./js/stockfish.js');
stockfish.addEventListener('message', function (e) {
console.log(e.data);
});
stockfish.postMessage('uci');
</script>
But I get the following error:
Security error: content located at file:///D:/ChessComparator/index.html cannot load data from file:///D:/ChessComparator/js/stockfish.js
.
I cannot run web workers on Chrome and I can't think of another browser to test this on.
答案1
得分: 1
最简单的解决这些问题的方法是避免在文件URI和其他null
来源上进行测试。
如果你只是想让它工作,尝试从源目录运行python -m http.server
或python3 -m http.server
来提供文件。然后,你可以在浏览器中访问http://localhost:8080
以在本地查看你的网页。
英文:
The easiest solution to these sorts of problems is to avoid testing in file URI and other null
origins.
If you just to get it working, try running python -m http.server
or python3 -m http.server
from the source directory to serve the files. Then you can visit http://localhost:8080
in your browser to view your webpage locally.
答案2
得分: -2
我发现默认情况下在Chrome本地上无法正常工作。如何在Chrome上使其工作,我不知道,但你可以使用Safari或Firefox。
英文:
i found that it just doesn't work in chrome locally by default. how to get it to work on chrome i don't know, but you can just use safari or firefox
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论