
Modern Programming Languages
Lecture # 38
The <script> Tag
• The <script> tag (<script>….</script>) in all major browsers interprets contents as
JavaScript unless one of the following occurs
– Inclusion of language attribute
<script language=“VBS”>….</script>
– Inclusion of type attribute
<script type=“text/javascript”>….</script>
• The type attribute is W3C recommended, it makes the language more common and in
many ways more useful
• <script> tag is used to delimit the script code from the HTML
– The script tag causes the browser’s JavaScript interpreter to be invoked, the
script run and any output produced
– The browser is considered the “host” environment
– There are other hosts for JavaScript and its variants
Location of Code
• JavaScript may be placed at three places
• In the <head> element
– Place scripts to be called or when event is triggered here
– Ensures script is loaded before called
<html>
<head>
<script type=“text/javascript”>
//script statements
</script>
</head>
Location of Code
• In the <body> element