Master Javascript by Typing PART III
Page 1A Summary of what we learned in last issue
In the second part of this tutorial we had a peek at what those perky
little things named functions are all about. We saw the different ways
of implementing functions in javascript.
OK ! Let's continue our trek through the land of Javascript.
CLASS III - Event Handlers
Understading the usage of Event Handlers is very important for successful
implementation of functions. Event Handlers are keywords that can be incorporated
into the HTML source code, and they are carried out when a particular
event happens. These events can be anything like the complete loading
of a page to the users hovering of mouse pointer over a predefined spot
in the webpage. Event handlers contribute greatly towards creation of
Dynamic Web Pages. All the event handlers in Javascript starts with on
keyword.
Format
<htmltag eventhandler = "code to be executed">
The htmltag part can be any valid html tag. The eventhandler
part can be any event handler like onLoad, onUnload, onClick etc. The
"code to be executed" part can be any javascript function or any
piece of javascript code.
To get a better understanding of event handlers lets take a look at one
of the examples we coded in last edition. In part - II of this article
we coded an example which showed some information about the browser used
by the client. We used a userdefined function called getClientBrowserInfo()
for collecting the browser information. The function was called
using the below given statement
<body onLoad="getClientBrowserInfo()">
Here the keyword onLoad is an event handler. It gets called when
ever a page completes its loading in a browser. So in this case the function
gets executed when the webpage is loaded completely.
Ok lets put the things that we learned about event handlers in to some
practical useful code. We are going to put a preloader for our webpage
using onLoad event handler & a little bit of javascripting. (A
Preloader is a small piece of information or animation (usually fat free
:-) shown to the user while the heavy duty web page loads in the behind.
Preloaders are needed only for pages with a great amount of content in
it)
|
|
