Hi, I'm sure this is the dumbest question ever, but I'm just getting started with Javascript and I'm baffled.
This code works fine, alert box pops up as expected:
<!DOCTYPE html>
<html>
<head>
<title>Test Page</title>
</head>
<body>
<p>This is a simple HTML page</p>
<script>alert("hello world")</script>
</body>
</html>
However if I strip out the Javascript into a separate file "script.js" then the alert box does not pop up. Here's the code for the html:
<!DOCTYPE html>
<html>
<head>
<title>Test Page</title>
</head>
<body>
<p>This is a simple HTML page</p>
<script src="script.js"></script>
</body>
</html>
and here's the contents of script.js:
alert(“Hello World“);
According to the course on Lynda.com that I'm trialling, this should work. However it doesn't work either on a website, or if the files are on my desktop and opened as local files. Tried Safari, Firefox, and Chromium with no luck, also no errors reported in Firebug that I can see.
Using Mavericks and BBEdit to generate the files. Code works when inline so I know the Javascript is actually enabled in the browser.
TIA for any pointers
Edit: Hmmm, apologies that the code indents don't seem to survive when I save the post
This code works fine, alert box pops up as expected:
<!DOCTYPE html>
<html>
<head>
<title>Test Page</title>
</head>
<body>
<p>This is a simple HTML page</p>
<script>alert("hello world")</script>
</body>
</html>
However if I strip out the Javascript into a separate file "script.js" then the alert box does not pop up. Here's the code for the html:
<!DOCTYPE html>
<html>
<head>
<title>Test Page</title>
</head>
<body>
<p>This is a simple HTML page</p>
<script src="script.js"></script>
</body>
</html>
and here's the contents of script.js:
alert(“Hello World“);
According to the course on Lynda.com that I'm trialling, this should work. However it doesn't work either on a website, or if the files are on my desktop and opened as local files. Tried Safari, Firefox, and Chromium with no luck, also no errors reported in Firebug that I can see.
Using Mavericks and BBEdit to generate the files. Code works when inline so I know the Javascript is actually enabled in the browser.
TIA for any pointers
Edit: Hmmm, apologies that the code indents don't seem to survive when I save the post