Entry
Can I put my client side JavaScript in a separate file and link it into a HTML document?
Mar 6th, 2000 08:13
Martin Honnen, Damien Sawyer,
Yes, the
SCRIPT
tag has a
SRC
attribute for that starting with JavaScript1.1/NN3 and IE4 (I think
IE3.02 also supports the SRC attribute though document.write inside the
included code doesn't work.). JavaScript files usually get a
.js
suffix and have to be served by the web server with mime type
application/x-javascript
to be treated correctly by the browser (otherwise they might show up as
plain text).
So a complete tag to link in an external JavaScript file looks like
<SCRIPT SRC="fileName.js" LANGUAGE="JavaScript"></SCRIPT>