Tutorial 16: Client-Side Scripting 101 - HTML with Style | 8 | WebReference

Tutorial 16: Client-Side Scripting 101 - HTML with Style | 8

index12345678

Tutorial 16: Client-Side Scripting 101

Defining the default scripting language

There is also a way to define the default scripting language for an entire document; this can be done by the Content-Script-Type HTTP header. If your server is not configured to send this header, you can include the equivalent META element in your document's HEAD element:

<META HTTP-EQUIV="Content-Script-Type" 
      CONTENT="applicationx-javascript">

You still have to specify the content type explicitly for each SCRIPT element in your document, however. So, you ask, why have Content-Script-Type? The answer is intrinsic event handlers.

Intrinsic event handlers

Intrinsic event handlers are ways to attach specific scripts to your documents that are executed only when something happens to an element. Not all event handlers apply to all elements, but here's the lot:

Intrinsic event handlers

ONLOAD (Script)
This event occurs when the browser finishes loading a document or a all frames in a frameset. It applies to BODY and FRAMESET elements.
ONUNLOAD (Script)
This event occurs when the browser stops displaying a document or a frame. It applies to BODY and FRAMESET elements.
ONCLICK (Script)
This event occurs when a mouse button is clicked over an element.
ONDBLCLICK (Script)
This event occurs when a mouse button is double-clicked over an element.
ONMOUSEDOWN (Script)
This event occurs when a mouse button is pressed over an element.
ONMOUSEUP (Script)
This event occurs when a mouse button is released over an element.
ONMOUSEOVER (Script)
This event occurs when the mouse is passed over an element.
ONMOUSEMOVE (Script)
This event occurs when the mouse is moved when it is over an element.
ONMOUSEOUT (Script)
This event occurs when the mouse is moved off an element.
ONFOCUS (Script)
This event occurs when an element recieves focus.
ONBLUR (Script)
This event occurs when an element loses focuse
ONKEYPRESS (Script)
This event occurs when a key is pressed and released over an element.
ONKEYDOWN (Script)
This event occurs when a key is pressed over an element.
ONKEYUP (Script)
This event occurs when a key is released over an element.
ONSUBMIT (Script)
This event occurs when a form is submitted.
ONRESET (Script)
This event occurs when a form is reset.
ONSELECT (Script)
This event occurs when text in a form control is selected.
ONCHANGE (Script)
This event occurs when a form control loses focus and its value has changed since gaining focus.

In order to use intrinsic event handlers, you must define the default scripting language using the Content-Style-Type header. I won't go into the details of how each of these handlers work; this is largely in the realm of scripting languages, not HTML. The one thing I will say is that instrinsic event handlers are a bad idea. Most scripting languages, including JavaScript, offer a way to define event handlers in scripts instead of using HTML attributes, and this is a better approach from a design point of view: If you decide to change the way your scripts work, what would you prefer, going through all of your documents and changing each event handler, or modifying one centrally maintained script? I think you get my point.

index12345678

URL: http://www.webreference.com/html/tutorial16/7.html

Produced by Stephanos Piperoglou
Created: September 15, 1999
Revised: September 27, 1999