Hello world problem

Just trying to display a javascript alert and for some reason the browser is just displaying the code

I have put the following into a file called test.js but it is just displaying all thie code in the browser - see http://www.mediakitchen.co.uk/test.js

I am sure this is something really basic. I have tried this in Firefox and IE



<html>
<body>
<script language=javascript>
//says the language is javascript

document.write("Hello World!"); //prints Hello World!

//stop JavaScript Code
</script>
</body>
</html>


Rename the file to test.html. Your web server serves the .js file with a MIME type of application/x-javascript, which browsers render as text.

Besides, don’t use language=javascript. The 1990s are over, long ago. Use <script type="text/javascript"> instead. The type attribute is required (while the language attribute is deprecated). It really should be type="application/javascript", but unfortunately Internet Explorer doesn’t support that (at least not older versions).

Also, you shouldn’t normally use document.write(). But that’s a bigger issue.

Doh! Thanks Cuckoo - of course it should have the extension html - too early in the morning for my brain.

Yeah sorry about the outdated script tag - I simply copied and pasted a hello world example from another site. Same goes for the document.write as this isn’t something I wanted to include anyway - just doing some debugging and wanted to display some values on screen.

Thanks

Paul