javascript text1 lesson2

Alert() boxes

hierarchy of objects

navigator

at the top in the navigator internat explorer or netscape

the navigator object has properties

we'll be using those properties to see which navigator the viewer is using (Navigator.appname)

the properties of the navigator cant tell the browser's name, version, and other neat stuff like what plug in are installed

window

right below navigator is window

the window object refers to each individual window that the navogator has opened

window properties include all sorts of cool stuff like size and tool bars

a window can do things

one thing a window can do is pop up some standardized boxes like alert() boxes

a characteristic of an object is a property

something an object can do is a method

The alert() box is a method of the window object

the alert() box

to make the alert() box

first way:

window.alert("hi");

second way

alert("hi");

zero th way

navigator.window.alert("hi");

write

<script language ="JavaScript">

alert("hi");

</script>

Put the above in the <head> of your page and a box will pop up when the line of code loads. The box will say "Hi, There!" and have an "OK" button. When you click the button, the page will finish loading

Now lets say we want the page to load before our box pops up. Whenever you want a response based on an Event, you must code a function and a function call

Lets put our alert() box in a function we'll call "box" and set it to run when the page fully loads. First we'll make the function:

function

<script language="JavaScript">
function box(){alert("Hi, There!");}
</script>

event

Now we need to code the event to make the function run. We'll use the "onLoad" event in the <body> tag to get this done:

<body onLoad="box()">

This will let the entire page load before the box pops up. Whenever an alert() box pops up, all other activities cease until the alert() box's "OK" button is clicked.

syntax

Some Syntax

The syntax of the alert() box is about as simple as it gets. Just type in "alert" and then code in a set of parentheses "()". Now fill in these parentheses with what you want the box to display. Words, or strings, must be put inside quotes like we've been doing.

You can use numbers, too. You don't need quotes for numbers. In fact, you can do a little math in your alert() box:

<script language="JavaScript">
function boxy(){alert(5+3);}
</script>

When the above box appears, it will display the number "8".

Exploring events

The alert box is a great tool for trying out new events. Here's a list of common events you can experiment with:

onClick -- Try putting this in the <body> tag. Now a function() will be called when the you click anywhere on the screen. Also works in links to add functionality to the usual HREF.

onUnload -- Put this in the <body> tag and the box will pop up when you leave the page. This event is how a lot of malicious webmasters "trap" you onto their site.

onBlur -- Put this in a <body> tag and the box will pop up whenever you you bring another window on top of the box's window. Making another window active is called "giving focus" to the window. Windows you put in the background are "blurred".

onFocus -- This is the opposite of "onBlur". The box will pop up when the window is brought to the top as the active window, or "focused".

There are some other events, but these are the ones you'll use the most: onMouseOver, onMouseOut, onClick, onLoad, and onUnload.


http://www.scriptsearch.com/cgi-bin/jump.cgi?ID=3878

 

résumé application

function

<script language="JavaScript">
function box(){alert("par ce chemin vous passez du guide touristique aux infos pratique");}
</script>

event

<a href="infospratiques.htm" onClick="box()">