Script stops working when hosted on Github Pages

前端 未结 1 1972
隐瞒了意图╮
隐瞒了意图╮ 2020-12-20 07:28

I built a random sentence generator -- when you click an HTML button, a random sentence is generated beneath it. The generation is powered by a simple script and jQuery.

相关标签:
1条回答
  • 2020-12-20 07:51

    If you open up your Developer Tools pane (in Chrome, right-click on the page and choose Inspect), you'll see this error in the Network console:

    Mixed Content: The page at 'https://bobbyfestgenerator.github.io/' was loaded over HTTPS, but requested an insecure script 'http://code.jquery.com/jquery-1.10.1.min.js'. This request has been blocked; the content must be served over HTTPS.

    You need to load your script over HTTPS instead of HTTP.

    The reason this works locally is because you're using the file:// scheme on your local machine (or http:// if you have a local development server). The browser doesn't have a problem loading an external script over HTTP in this case.

    However, Github Pages is hosting your file over HTTPS (a secure connection) for you. For security reasons, the browser won't load a script over HTTP if the page is hosted on HTTPS.

    Just change the code in your <head> tag to load the script over HTTPS:

    <script src="https://code.jquery.com/jquery-1.10.1.min.js"></script>
    
    0 讨论(0)
提交回复
热议问题