C3. Client Side Scripting
Client Side Script Applications refers to
those programs that run on the Web client (browser), after or during loading Web
pages. Client Side Script programming languages are those languages that allow
writing of such applications. These applications are either embedded in HTML and
supported directly by the browser (ex. JavaScript) or require an external
plug-in (ex. ActionScript - Flash). Besides the use of scripting languages to
implement Client Side Applications programming languages can be also used (eg
Java via Java Applet interface).
JavaScript
The JavaScipt
is a scripting language supported by most Web browsers. It can be integrated
directly into an HTML page. Unlike other languages, it has some important
advantages such as:
- does not require installation of additional
applications to run
- is easy to learn (the syntax is close to C or
Java)
- allows implementation of complex applications in
a simple manner
- can access and contorl all HTML entityes (as
text, images, forms, frames, etc.)
- supports the validation of HTML forms
- allows event-based programming
A major JavaScript feature is
the ability to add dynamism and interactivity to Web pages. An example is
offered by Dave Tau in the presentation web page of the JavaScript 2nd
Ed:
Javascript is case sensitive. Statements can be (optionally)
separated by ";". Like in the C language code sequences can form compound
instructions if they are placed between braces. For comments Java syntax can be
used on a single line comments (/ /) or ovet multiple lines (/*...*/). To
include a sequence of JavaScript code into an HTML page the tag
<script> have to be used (see E3.1):
<script type =
"text/javascript">
// the JavaScript
code
</script>
The code position in the page depends on when it
is intended to run. In section <head> goes the user defined
functions. Code written into the <body> section will run in the browser
while loading that part of the page. There may
be multiple JavaScript sections in a page. For long sequences of
code or reusable code an external JavaScript file can be
included:
<script type="text/javascript"
src="fisierCod.js">
</script>
User defined
functions have to have a name, a parameter list and a code block. If the
function calculates a value, it can be returned using the return
instruction. A special kind of functions are called Events. They are actions
that are detected by the browser and can cause execution of a function. The main
events captured by the JavaScript are: onLoad, onUnload, onFocus, onBlur,
onChange, onsubmit, onMouseOver, onMouseOut. More information on events can be
found at Elated
Communications.
Try..
catch sequences can be used for error handling. The throw are designed
for custom error generation. More information can be found at
W3Schools - JS error
handling.
The DOMThe DOM (Document
Object Model) gives generic access to most elements, their styles and
attributes in a Web document. Each HTML document loaded into a browser window
becomes a Document object handled by the browser.
The DOM structure
is:

(img: Wikimedia)
For more
information please consult
JavaScript
Kit.com.
VBScriptThe VBScript (Visual Basic
Scripting) is a Microsoft scripting language. It is used mostly in conjuction
with ASP server side technology and work best with Internet Explorer
browser.
Like JavaScript, the VBScript code is written within paired
<script> tags inside <head> and/or <body>
section.
<script language="VBScript">
<!--
VBScript code-->
</script>
Main language structures can be
fond at
Microsoft
- VBScript fundamantals.
Some VBScript examples are hosted by
Cruto
Creations.
Action Script
The Adobe (Macromedia)
ActionScript is a scripting language used mainly for development of
features in Adobe Flash applications. Action script goes into external .swf
files that runs in Adobe Flash Player or Flash browser plug-in. Is not possible
to embed Action script into a HTML page.
ActionScript was originally
developed by Macromedia and now belongs to Adobe, which acquired Macromedia in
2005. The language is based on ECMA standard. It was created for 2D vector
drawing and animation control, but over time evolve to realize complex web
applications or even Web games. ActionScript is case-sensitive. The current
version is Actionscript 3.0.
More information on Adobe Flash and
Action Script on
Flash
Tutorial at webdevelopersnotes.com.
Slides:
C3. Client Side
Scripting.