I am testing out a JavaScript on a page and it is not working. It hasn’t been working for a long time.
Hello!
Could you please elaborate on the question? Thanks!
Have you checked your settings and enabled javascript?
How would I do that? (enabling JavaScript)
could you post a link to the webpage thats not working, thanks
You’ll have to use HTML on the site.
HTML5
<!DOCTYPE html>
<html>
<head>
<script src="file.js"></script>
</head>
</html>
HTML4
<html>
<head>
<script src="file.js" type="text/javascript"></script>
</head>
</html>
Here are some common problems
#1 - You’re using jQuery, but you don’t have the CDN
This results in an error like this:
Uncaught ReferenceError: $ is not defined
You will then need to put the CDN too:
<script src="https://code.jquery.com/jquery-3.5.1.js"></script>
SO many questions on stackoverflow are because of this!!!
#2 - You’re missing the async
or defer
attributes to your script file (if needed)
When present, it specifies that the script is executed when the page has finished parsing
#3 - And, you have some bugs
Please check your console in Developer tools CTRL SHIFT I
LOL I don’t even think HTML4 is in use anymore!
Some sites are in HTML4.
I went through and checked all the following corrections and none of them work. Sorry! If you have any other information, please reply.
- Your URL is not correct. For example, your JavaScript is in
/htdocs/script/index.js
. If your file is in/htdocs/index.html
, and you use<script src="index.js"></script>
, it won’t work. If you use<script src="/script/index.js"></script>
or<script src="script/index.js></script>
, it works. - Your file is not JavaScript. Extensions end with
.js
- Your JavaScript file has an error.
- You are not using
.html
files or.php
files.
Yes, but it’s not a good idea to use HTML4 anymore (unless your site is targeting oldies or people who like really old browsers).
As far as I know, chrome switched to HTML5 all the way back in 50.
Ok, HTML5 is a bit newer than I thought, but it still is old enough that the majority of internet users probably use it.
If you really want high compatibility for your website, then sure go ahead and use HTML4.
Otherwise, HTMl5 is plenty good.
This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.