Javascript file not working on github pages [duplicate]

元气小坏坏 提交于 2019-12-01 13:12:37

问题


I am able to load my javascript file on the local machine. But on github pages, it is not working.

I have included the file in index.html as

<script src="script.js" type="text/JavaScript"/>

The website is https://abhikulshrestha22.github.io./

The code is at https://github.com/abhikulshrestha22/abhikulshrestha22.github.io

Any help would be appreciated. Thanks in advance.

Edit 1 I tried to add the following code in my javascript file to check if its working, but it is not working on github page and working locally.

$(document).ready(function(){
    alert("hi");}

回答1:


Try this

<script src="script.js" type="text/javascript"></script>

Use closing script tag.

For more check this answer.




回答2:


<script> tags need a closing tag even if they load an external script.

Your forgot it, so it tries to run </body></html> instead.




回答3:


I think the issue is with wrong spelling.

Try this:

<script src="script.js" type="text/javascript"/>

I would advise you to move js files in a js directory on the root, following some best practices.



来源:https://stackoverflow.com/questions/51261710/javascript-file-not-working-on-github-pages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!