Freelance Writing Jobs | Today's Articles | Sign In

 
Browse Sections

The Script Tag


  • Level: Basic
  • Skills Required: Introduction to JavaScript


Abstract:

HTML specifications define a tag <SCRIPT> so that browsers can identify start of some script. There are two attributes that can go with this tag and we will see them in detail in this article.


The Tag:

Browsers handle HTML from top to bottom and evaluate / perform scripting functions as they go. You can put <SCRIPT> tag anywhere in your document. Usually, the head part is where JavaScript is put. The reason is simple: Web browsers handle the head part before the rest of your page. The general form of <SCRIPT> tag is as follows:

   :
<script language="JavaScript">
<!-- // hiding from old browsers
   :
// -->
</script>
<noscript>
   :
</noscript>
   :

The script tag defines the start of JavaScript. The comments after it hide JavaScript from browsers that do not know it. However, you can safely remove the comments in case of JavaScript since both the big browsers as well as Opera support JavaScript. The <NOSCRIPT> tag is used for browsers that do not support your scripting language. You can put a message in between <noscript> and </noscript> to inform the user that his browser doesn't support the scripting language.


The language Attribute:

JavaScript is one of the many scripting languages being used today. The language attribute of the <script> tag defines which language you are using. A popular alternative to JavaScript is VBScript; however, its not supported by Netscape Navigator. Even when you are using JavaScript, you can use different versions of it. A given browser supports only some of them. The following chart will help you understand the relationship between JavaScript versions and web browsers.

Language Navigator 3.0 Navigator 4.0 IE 3.0 IE 4.0
JavaScript x x x x
JavaScript1.1 x x x
JavaScript1.2 x
JScript x

If you are using JavaScript1.2 you can use the script tag as <script language="JavaScript1.2">. JScript is Microsoft's counterpart of JavaScript. Its quite similar to version 1.2 of JavaScript but the differences become annoying when you move on to CSS and DHTML.


SRC Attribute:

Another less commonly use attribute is SRC. You can use it do define the source file of the script. This can be very handy when you need a few JavaScript functions on several pages. You can write all your common functions in a single file and save it with an extension of .js.

The copyright of the article The Script Tag in JavaScript is owned by Muhammad Ali Shah. Permission to republish The Script Tag in print or online must be granted by the author in writing.

Go To Page: 1 2

Articles in this Topic    Discussions in this Topic