Because HTML doesn't actually have scripting capability, you need to use the
Triggering a ScriptIn many cases, you won't want the script to run automatically. You might only want the script to run if the user does something (like hover over a link), or once the page has finished loading.
These actions are called intrinsic events (events for short). There are 18 pre-defined intrinsic events that can trigger a script to run. You use event handlers to tell the browser which event should trigger which script. These are specified as an attribute within the HTML tag.
Lets say you want a message to display in the status bar whenever the user hovers over a link. The act of hovering over the link is an event which is handled by the
onmouseoverevent handler. You add the
onmouseoverattribute to the HTML tag to tell the browser what to do next.
Treat yourself to a onMouseover="window.status='Go on, you know you want to'; return true">Killer Ab Workout
Before we move on, check out the list of intrinsic events as specified by HTML 4.01
Calling an External ScriptYou can also place your scripts into their own file, then call that file from your HTML document. This is useful if you want the same scripts available to multiple HTML documents - it saves you from having to "copy and paste" the scripts into each HTML document. This makes it much easier to maintain your website.
Alternate Information for Older BrowsersYou can also provide alternative info for users whose browsers don't support scripts (and for users who have disabled scripts). You do this using the
Set a Default Scripting LanguageYou can specify a default scripting language for all your
scripttags to use. This saves you from having to specify the language everytime you use a script tag within the page.