A script is a small, embedded program that can add interactivity to your website. For example, a script could generate a pop-up alert box message, or provide a dropdown menu.
Because HTML doesn’t actually have scripting capability, you need to use the <script> tag to generate a script, using a scripting language.
The <script> tags tell the browser to expect a script in between them. You specify the language using the type attribute. The most popular scripting language on the web is JavaScript.
In either case, a generally accepted convention is to place your scripts between the <head></head> tags.
<script type=”text/javascript”>
alert(”I am a script. I ran first!”)
</script>
Athough most (if not all) browsers these days support scripts, some older browsers don’t. If a browser doesn’t support JavaScript, instead of running your script, it would display the code to the user. To prevent this from happening, you can simply place HTML comments around the script. Older browsers will ignore the script, while newer browsers will run it.
<script type=”text/javascript”>
<– Hide from older browsers
alert(”I am a script. I ran first!.”)
Unhide –>
</script>
