我按照这些步骤编写了一个演示 HTML。以下是https://github.com/commonmark/commonmark.js#commonmarkjs README 中的步骤:
对于客户端使用,您可以
make dist
生成一个独立的 JavaScript 文件js/dist/commonmark.js
,适合链接到网页,或者从 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
,并用 Firefox 55.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
到本地文件系统的情况下解决此错误? - 这是我上面引用的 commonmark.js README 文档中的错误,还是我对文档的理解有误?