JavaScript

Tuesday April 8, 2025
updated: April 10, 2002

 
Home
Getting Started
Lesson 1
Lesson 2
Lesson 3
Lesson 4
Lesson 5
Lesson 6
Lesson 7
Lesson 8
Resources
Credits

 

 


Lesson 6 Examples: Event Handlers

Using onClick for a Back Button
When clicked the arrow button, adjacent to the java code below, will load the previous URL in the History list. This means it is equivalent to the brower's Back button!

The Code for the script is:

<a href="#" onClick="history.go(-1)">
<IMG SRC="Back.JPG"></a>

back button

The Java code is embedded in the HTML link tag.

  • The onClick event is placed within the link tag
  • the onClick event handler executes the code, history.go(-1) when the link is clicked
  • history.go(-1) loads the previous URL address in the history list
  • history.go(1) would load the the next URL in the history list
  • history.go(location) would load a specified URL from the history list

Using onMouseOver to change Status Bar

The Function is called using the onMouseOver event handler:

rollover button

<a href="#" onMouseOver="window.status='On rollover button';return true"
onMouseOut="window.status='Off rollover button';return true" >
<img src="imagefile.gif"></a>

Again the Java code is embedded in the HTML link tag.
  • The onMouseOver and onMouseOut event handlers are placed within the link tag
  • The object status bar will display the text in the single quotation marks
  • The semi colon is used to separate the java statements

© 2002 Tracy Johnson