我遵循这些步骤并编写了一个HTML演示。以下是https://github.com/commonmark/commonmark.js#commonmarkjs自述的步骤:
对于客户端的使用,您可以执行
make dist来生成一个独立的JavaScript文件js/dist/commonmark.js,该文件适合链接到web页面,或者从https://raw.githubusercontent.com/jgm/commonmark.js/master/dist/commonmark.js或bower install commonmark获取最新的文件。
这是我的演示HTML。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script src="https://raw.githubusercontent.com/jgm/commonmark.js/master/dist/commonmark.js"></script>
<script>
window.onload = function() {
console.log(commonmark)
}
</script>
<body></body>
</html>下面是我的演示的JSFiddle URL:https://jsfiddle.net/y3xohp7x/
我在本地将这个HTML保存在一个名为foo.html的文件中,并使用Firefox55.0.1打开了这个本地文件。
但是,如果我用Firefox 55.0.1加载它,则控制台中会出现以下错误。
Loading failed for the <script> with source “https://raw.githubusercontent.com/jgm/commonmark.js/master/dist/commonmark.js”. foo.html:5
ReferenceError: commonmark is not defined foo.html:9:5问题:
commonmark.js复制到本地文件系统的情况下解决此错误?发布于 2017-08-16 02:27:51
编辑
实际上,对于github内容,显然有一种方法可以做到这一点:https://rawgit.com/
这个网站给你一个链接到一个版本的脚本,将与正确的MIME类型提供服务。
因此,这将为您正确加载脚本:
<script type="application/javascript" src="https://cdn.rawgit.com/jgm/commonmark.js/master/dist/commonmark.js"></script>https://jsfiddle.net/w1uvq59r/
原始答案
原因是脚本源被发送回标头:
"Content-Type": "text/plain"
"X-Content-Type-Options": "nosniff"后一个标题阻止浏览器执行脚本,因为内容类型是不可执行的,比如"application/javascript“。这意味着不幸的是,没有办法让脚本远程加载。Here is a thread with more information on a similar problem.
据我所知,唯一的解决方案是在本地加载它,如下所示:
<script type="application/javascript" src="path/to/the/file.js"></script>https://stackoverflow.com/questions/45703895
复制相似问题