[英]Javascript won't run on github pages site
<!-- 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. 用https
替换http
,你应该好好去。 This error is easily discoverable if you open the Javascript Console in your browser (usually under F12). 如果您在浏览器中打开Javascript控制台(通常在F12下),则很容易发现此错误。
<!-- correct -->
<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
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. 拼出https://cdnjs.cloudflare.com/
更好。
Here's why: 原因如下:
file://
URI, which is sometimes helpful during development. 如果您通过file://
URI在本地打开页面,该页面仍然有效,这在开发过程中有时很有帮助。 Some advice from Paul Irish , one of developers behind Chrome: Chrome开发人员之一Paul Irish的一些建议 :
If the asset you need is available on SSL, then always use the
https://
asset. 如果您需要的资产在SSL上可用,则始终使用https://
asset。It's always safe to request HTTPS assets even if your site is on HTTP, however the reverse is not true. 即使您的站点在HTTP上,请求HTTPS资产也始终是安全的,但反之则不然。
当您使用非指定的 http protocols
,最好不要将它们放在任何请求中......所以,而不是http://
仅使用//
。
console.log("$", window.jQuery)
<script src='//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.