I am new to Javascript and can't seem to load a simple Javascript file from an html file.
I have a folder on my desktop with an .html file and a .js file
The .html file contains the following html:
<html>
<head>
<title>Simple Page</title>
</head>
<body>
<p> this is a very simple HTML page</p>
<script src=“script.js”></script>
</body>
</html>
Inside my .js file I have the simple Javascript text:
alert("Hello world:);
When I open my .html file in a browser I just get the text:
"this is a very simple HTML page"
It doesn't run the script. I can't seem to find a way to make the .html file point to the .js script even though they are in the same folder on the desktop. What am I doing wrong? Also, I've tried to put the Javascript directly inside the html code (with the ( tags) and it doesn't work either.
What am I doing wrong? I've tried two different browsers. Is it a folder issue?
Thanks.
I am new to Javascript and can't seem to load a simple Javascript file from an html file.
I have a folder on my desktop with an .html file and a .js file
The .html file contains the following html:
<html>
<head>
<title>Simple Page</title>
</head>
<body>
<p> this is a very simple HTML page</p>
<script src=“script.js”></script>
</body>
</html>
Inside my .js file I have the simple Javascript text:
alert("Hello world:);
When I open my .html file in a browser I just get the text:
"this is a very simple HTML page"
It doesn't run the script. I can't seem to find a way to make the .html file point to the .js script even though they are in the same folder on the desktop. What am I doing wrong? Also, I've tried to put the Javascript directly inside the html code (with the ( tags) and it doesn't work either.
What am I doing wrong? I've tried two different browsers. Is it a folder issue?
Thanks.
Share Improve this question edited Nov 14, 2014 at 21:28 Shriike 1,3419 silver badges20 bronze badges asked Nov 14, 2014 at 20:44 tvalletvalle 11 silver badge3 bronze badges 4- Which browsers have you used? I know chrome and IE will have issues doing this. Have you tried firefox? – Wet Noodles Commented Nov 14, 2014 at 20:46
- 2 alert ("Hello World"); " instead of : – user3740097 Commented Nov 14, 2014 at 20:46
- Is javascript enabled in your browser? Also, as @8BitProgrammer pointed out, you have a colon instead of a closing quote in your alert call. – user3542456 Commented Nov 14, 2014 at 20:46
- Are you getting errors in the Javascript console? What are they? – Barmar Commented Nov 14, 2014 at 20:47
4 Answers
Reset to default 4Three possibilities I can see here:
Your script has a colon instead of double quote
If the (1) is just a copy/paste error - your double quotes over "script.js" are wrong type (if you have copied/pasted this code from somewhere - just type them manually)
JavaScript is disabled in your browser(some browsers such as Internet Explorer will not load the JavaScript unless it served from a webserver such as apache or IIS for example).
To test if it is a browser issue place the javascript in a
<script></script>
tag right before the closing</body>
tag. If it works using the following code then it an issue with your browser.
Example:
<script>
alert("hello world");
</script>
</body><!--above script should be placed before this tag -->
You have a syntax error in your Javascript code. Change the :
after world
to "
.
alert("Hello world");
You have the wrong types of quotes in your <script>
tag. You have to use plain, ASCII double quotes, not curly quotes.
<script src="script.js"></script>
I see a couple of issues:
(1) There's syntax error with your javascript. It should be (note double quote to end string):
alert("Hello world");
(2) Your double quotes were off in my text editor. It should be:
<script src="script.js"></script>