> Peter Afonin wrote:
I have a JavaScript that I need to use in many pages. How do I create JS
includes?
"Cycloneous Echevarria" topposted Peter this is how:
<html>
<head>
<title>Test!</title>
<!-- now include script tag with src attribute pointing to -->
<!-- to your script -->
<script language="javascript" type="text/javascript" src="test.js">
<!-- //
// -->
</script>
</head>
<body>
Hello World!
</body>
</html>
A nice bare-bones example. Two remarks on the side: The script element has
no language attribute. It may have had one in the past, but that is history.
To reduce unnecessary webtraffic and in order to "validate", you should
remove the portion which reads <... language="javascript" ...> from the
script tag. Also, the custom of hiding script from older browsers by
encapsulating the script's content in <!-- --> SGML comments is obsolete.
These "older browsers" that do not know about the script tag, are history
too.
You can also make the src point to a script on another website. Socalled
hit-counters often do this. Simply by entering the whole address, including
http protocol. Just be aware that cross-domain security restrictions apply.
As a last remark, a script element that has a src defined, will ignore any
content inside the tag itself. Only if the source file is not found or there
some other error loading the external script, will the engine consider and
execute any script hardcoded inside the tag.
HTH
Ivo