JavaScript不会在github页面上运行 [英] Javascript won't run on github pages site

查看:111
本文介绍了JavaScript不会在github页面上运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,JavaScript曾经在我的github页面上工作,但在删除存储库并尝试重新上传项目并进行一些更改后,它不再适用。以下是回购。这里是网站

解决方案

您通过HTTPS提供站点服务,但尝试通过HTTP加载jQuery。这是不允许的。



 <! -  wrong  - > 
< script src ='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'>< / script>

http > https ,你应该很好去。如果您在浏览器中打开Javascript控制台(通常在F12下),该错误很容易被发现。

 <! -  correct - > 
< script src ='https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'>< / script>






但是协议相关链接怎么样?



您也可以使用这种曾经流行的语法:

 <! -  -  meh  - > 
< script src ='// cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>

但在这一点上它是货真价实。拼出 https://cdnjs.cloudflare.com/ 更好。



原因如下:





来自Paul Irish的一些建议,Chrome背后的开发人员之一: b
$ b


如果您需要的资产可用SSL,然后始终使用 https:// 资产。



请求HTTPS资产总是安全的,即使您的网站在HTTP上,但反过来却是不正确的。



So the javascript used to work on my github pages site but it doesn't work anymore after I delete the repository and tried to re-uplaod the project with some changes. Here is the repo. Here is the site.

解决方案

You are serving the site over HTTPS but trying to load jQuery over HTTP. This is not allowed.

<!-- wrong -->
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>

Replace http with https and you should be good to go. This error is easily discoverable if you open the Javascript Console in your browser (usually under F12).

<!-- correct -->
<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>


But what about protocol relative links?

You could also use this once-popular syntax:

<!-- meh -->
<script src='//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>

but it's cargo cult at this point. Spelling out https://cdnjs.cloudflare.com/ is better.

Here's why:

Some advice from Paul Irish, one of developers behind Chrome:

If the asset you need is available on SSL, then always use the https:// asset.

It’s always safe to request HTTPS assets even if your site is on HTTP, however the reverse is not true.

这篇关于JavaScript不会在github页面上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆