Home > Articles > Programming > JavaScript

  • Print
  • + Share This
This chapter is from the book

Q&A

  1. I noticed that the <img> tag in HTML can't have onMouseOver or onClick event handlers in some browsers. How can my scripts respond when the mouse moves over an image?

  1. The easiest way to do this is to make the image a link by surrounding it with an <a> tag. You can include the BORDER=0 attribute to prevent the blue link border from being displayed around the image. You'll see an example of this in Hour 13.

  1. My image rollovers using onMouseOver work perfectly in Internet Explorer, but not in Netscape. Why?

  1. Re-read the previous answer, and check whether you've used an onMouseOver event for an <img> tag. This is supported by Internet Explorer and Netscape 6, but not by earlier versions of Netscape.

  1. What happens if I define both onKeyDown and onKeyPress event handlers? Will they both be called when a key is pressed?

  1. The onKeyDown event handler is called first. If it returns true, the onKeyPress event is called. Otherwise, no keypress event is generated.

  1. When I use the onLoad event, my event handler sometimes executes before the page is done loading, or before some of the graphics. Is there a better way?

  1. This is a bug in some older versions of JavaScript. One solution is to add a slight delay to your script using the setTimeout method. You'll learn how to use this method in Hour 11, "Using Windows and Frames."

  1. When I try the descriptive links example in Netscape 6.2, the descriptions don't display. Why not?

  1. At this writing, the latest version of Netscape 6 fails to display the descriptions if your link includes the HREF attribute. One way around this is to use an onClick event handler instead, as in <a onClick="location.href='newpage.html';">. This works, but Netscape doesn't display it in the correct link color.

  • + Share This
  • 🔖 Save To Your Account