--== Tags ==--

[ Previous Section | Home | Index | Test Your HTML | Related links | Next Section ]



Now that you have learned how objects work you'll want to be able to incorporate a script into your page. To do this you need to learn the script tag. This tag allows you to include pieces of Java Script into you page. When using the <Script&g t; tag you must tell the browser what type of Script you are using. To do this we include the Language=JavaScript attribute. So our new tag becomes <Script Language=JavaScript>. An example of using the script comm and follows.

<HTML>
<Head>
</Head>
<Body>

<Script Language=JavaScript>

Your Java Script goes here

</Script>
</Body>
</HTML>

Note: The <script> tag can go anywhere on the page. It works best in the body right were you want to run it. Later when we get into functions you can define your own functions and new objects in the Head. In that case y ou might have more than one section of Java Script on your page.

Note: Not all browsers support Java Script. For non-Java Script capable browsers, any text that is script appearing between the Script tags will be printed as part of your web page. To avoid this problem you can use comment tags to comment out the script for non Java capable browsers. In Java, comments can be added on lines using two forward slashes "//" or as in C and C++ a forward slash followed by an asterick at the beginning of the comment and an asterick followed by a forward slash at the end.


Two ways to comment lines (commenting a line means that it will not be executed by the Script).

<Script Language=JavaScript>

Your Java Script goes here
// Comments go here
/*comments go here
unitl you end it*/

</Script>


To hide the Java Script from non Java capable browsers you would do the following

<HTML>
<Head>
</Head>
<Body>

<Script Language=JavaScript>
//Java Script appears Here
//Download Netscape Navigator 2.0 to use it.

<!--hiding from other Browsers

Your Java Script goes here

// Stop hiding from other Browsers -->
</Script>
</Body>
</HTML>

One other attribute that you can set in the script tag is the src or source. If your Java Script is too long to put in your web page you can put it in a seperate file. You tell the Browser where this file is by using the src at tribute. Here is an example, let's say our Java Scriptwasin the file called java.js

<HTML>
<Head>
</Head>
<Body>

<Script Language=JavaScript src="java.js">

Your Java Script goes here

</Script>
</Body>
</HTML>


Note: When using a seperate Java Script file the name must have an extension of .js

Note: The src attribute works the same as the img= or href=.




[ Previous Section | Home | Index | Test Your HTML | Related links | Next Section ]