Overview
of JavaScript.
However, confusion still reigns, since we now have Java and javaScript.. These two languages are completely different to each other, sharing only a similar sounding name.
JavaScripts can read and placed directly into HTML pages | "Applets" are executed externally, and are not embedded in HTML pages |
Easier to understand and use in HTML | Requires a sound programming background to create and use |
Object based | Object oriented |
Limited capability & features | Wider range of capabilities & features |
Can run on on 16 & 32-bit operating systems without penalty to capabilities. | Requires 32-bit operating system to make full use of it. |
The power behind JavaScript is in it's
use of functions. Functions are basically mini 'scripts' within the
main script that each have a specific purpose or task. Functions should
always be defined between the <HEAD>
and </HEAD> tags. This allows them
to be loaded before the web page has been fully loaded, so that any script
on your page will work when the viewer starts to browse.
Functions are defined by first giving each function a unique name by which it can be identified within the script itself. This naming system is case sensitive, so, function Lookup is different to function lookup. Here's an example of a JavaScript function called expnew. It's sole task is to check the current date system date against the date it is given, and if this date has not been reached yet then it will display an Icon on the web page. <script language="Javascript">
;Start of a JavaScript routine.
// please keep these
lines on when you copy the source ;// Denotes comment lines,
var image = "new.gif"
;Define a global variable called image
function expnew(when)
{
;Start of our function called expnew
;{ denotes start of function code when = new Date(when)
;variable when is defined as a local
if (when.getTime()
> date.getTime()) {
;if when > date then display the new.gif
}
;{ denotes end of script code
Ok, we now have a defined script function and if placed in a html web page will do nothing, since it must now be executed by a specific call to this function we have called expnew. In order to do this we must place a separate script instruction on our HTML page which must also be enclosed within the <script> or and </script> tags. See below on how we can expand on the starting <script> tag to control which Netscape Browser can execute our script code. Each time we want the expnew function to be executed we must place the following script code in our HTML page, preferably where we want the Icon to be displayed. <script language="Javascript">
;Start of a JavaScript routine.
//--> ;//--> Stop ignoring script code </script>
;</script> denotes end of script code
|
Here's this script in action..
This
"New" Icon expired on 12/20/98
|