JavaScript 不在 github.io 上执行,但在本地运行

标签 javascript github github-pages

我的 HTML 中有以下 JavaScript:

<script> 
// This is not needed when the the style is set in _layouts/base.html 
// document.body.style.visibility = 'hidden'; 
function makeBodyVisible() { document.body.style.visibility = 'visible'; } if (window.addEventListener) window.addEventListener("load", makeBodyVisible, false); 
else if (window.attachEvent) window.attachEvent("onload", makeBodyVisible); 
else window.onload = makeBodyVisible; 
</script> 

但是,当页面加载时,它仍然隐藏。我还检查了是否创建了 window.onload 或任何其他事件监听器(使用 getEventListeners),但没有创建。这让我相信脚本没有运行。奇怪的是,这种情况只发生在我的 github.io 页面上,而在本地却发生了。 有人可以告诉我发生了什么事吗? 这是网站:https://botev.github.io/

最佳答案

我查看了您在答案中链接的网站 - 看起来这个脚本被注释掉了!因此不会运行。 附上截图。

Screenshot of production code for https://botev.github.io/, showing the script in question is commented out.

关于JavaScript 不在 github.io 上执行,但在本地运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49366300/

相关文章:

markdown - 如何在没有 index.html 的情况下使用 Jekyll-paginate?

deployment - 如何将中间人站点部署到 GitHub 用户页面

Javascript 文件无法在 github 页面上运行

github - 如何在 Github 上提交并在 Basecamp 上自动标记为完成?

git - 我们如何处理公共(public)存储库中的私有(private)配置文件?

javascript - 使用 Object.create(null) 创建 JS 对象是否与 {} 相同?

javascript - 通过 CLI 将 URL 传递给 CasperJS

javascript - 如何从有一些链接的图片弹出一个新窗口?

javascript - 未使用模态 Bootstrap 和 codeigniter 插入数据

.net - 在我使用 NuGet 的项目上使用 github