Wednesday, May 18, 2011

Reading Notes - Ch. 6

Each of the things that happen in a web page are Events.

Functions and Events
Inline Events
The simplest way to run a function when an event fires is called inline event registration.
 Assign an event handler.

<a href="page.html" onmouseover="alert('this is a link');">A link</a> 

You can even use the inline technique to call a previously created function, like this:
<body onload="startSlideShow()">

**You can add the event handler directly to the HTML but then it gets messy when trying to update the site in the future. It is a best practice to have a separate the Javascript.

Traditional Model
Assign (inside the head) an event handler  to a page element.

If you have a function and call it usually it looks like:
window.onload=message( );  
When you have parenthesis you are telling it to run immediatly

If you remove the parenthesis you are letting the onload handler know what to do when the time comes.
window.onload=message;  // the message loads after the page is finished loading


No comments:

Post a Comment