JavaScript
was developed by Netscape not Sun Microsystems.
Many people think JavaScript and Java are linked liked
Visual Basic and VB Script are, they are not. It is
just a marketing ploy, the original name was LiveScript.
The Server-side JavaScript is still call LiveWire.
Depending
on which browser you are using there are different versions
of JavaScript
Version
Netscape
support
IE
support
JavaScript
1.0
JScript 1.0
Navigator
2.X
IE
3.X
JavaScript
1.1
Navigator
3.X
N/A
JavaScript
1.2
JScript 3.0
Navigator
4.0 to 4.05
IE
4.X
JavaScript
1.3
Navigator
4.06 to 4.7X
N/A
JavaScript
1.4
JScript 5.0
N/A
IE
5
JavaScript
1.5
JScript 5.5
Navigator
6.X
IE
5.5 to 6.X
Embedding
JavaScript into HTML
JavaScript can to placed in the <HEAD> or/and
the <BODY> of the HTML document.
<HTML>
<HEAD>
<TITLE>Welcome to VisualTech</TITLE> <SCRIPT LANGUAGE="JavaScript">
<!-- // JavaScript Code
Here
// -->
</SCRIPT>
</HEAD>
<BODY> HTML Code Here <SCRIPT LANGUAGE="JavaScript">
<!-- // JavaScript Code
Here
// -->
</SCRIPT> HTML Code Here
</BODY>
</HTML>
The
browser will automatically use the newest version of JavaScript
it knows.
If you have developed the web page that needs JavaScript
version 1.5 you can tell the browser which version to
use. <SCRIPT
LANGUAGE="JavaScript1.5">
<!-- // JavaScript 1.5 Code
Here
// -->
</SCRIPT>
If
the browser doesn't support JavaScript version 1.5 the
browser with ignore the entire block of code.
Adding
External JavaScript from a File
If you have a block of JavaScript code the you are going
to use on more then one web page you can save it to a
file. Then import the file. <SCRIPT LANGUAGE="JavaScript"
SRC="FileName.js">
<!-- // JavaScript Code If
File NOT Found
// -->
</SCRIPT>
If the file is not found the JavaScript code between the
<SCRIPT> tags will be used.
What
if a Browser doesn't Support JavaScript
If a browser hits your web page that doesn't support
JavaScript use the tags <NOSCRIPT> after to <SCRIPT>
to warn the user. Also the reason why inside the <SCRIPT>
tags around your JavaScript code you put the comment
tags <!-- and // --> is that if a browser doesn't
support the <SCRIPT> tag it will skip it. The
comment tags will comment out your JavaScript for the
browser doesn't try to read it as HTML code. <SCRIPT
LANGUAGE="JavaScript">
<!-- // JavaScript Code
Here
// -->
</SCRIPT> <NOSCRIPT>
// HTML Code to warn the
user
</NOSCRIPT>
Comments
is JavaScript
// - Single Line Comment
/* */ - Multiple-line Comment
User
Messages
If
you want a simple message box use the alert function. alert("message")
If you want an input message box to get input from the
user use the prompt function.
It will return a string. If the user select Cancel it
will return a blank string. prompt("message","Default
text")
If you want to ask the user a yes or no question use
the comfirm function.
It will return a true to false result. comfirm("Question to user")
Example:
<HTML>
<HEAD>
<TITLE>Prompt Example</TITLE> <SCRIPT
LANGUAGE="JavaScript">
<!--
function bye() { alert("Thank
you for visiting us.");
}
// -->
</SCRIPT>
</HEAD>
<BODY onUnload="bye()"> <SCRIPT LANGUAGE="JavaScript">
<!--
document.write("Welcome " + prompt("Want
is your name?","") + " to VisualTech");
// -->
</SCRIPT>
</BODY>
</HTML>
Copyright 2002 VisualTech Components. All Rights Reserved.