Using the NS4 event Object


Using the NS4 event Object

In Netscape Navigator 4.0, you can capture and release events with methods such as captureEvents , disableExternalCapture , enableExternalCapture , handleEvent , releaseEvents , and routeEvent (see Chapter 6).

Here's an example targeted to that browser that shows how to capture events. By default, when you click a button labeled Click Me! in this example, an alert box appears with the message Button saw the event . On the other hand, events in this browser start at the top of the object hierarchy and move downward; so if we capture the event in the document object with the captureEvent method, that event won't get down to the button. You can do that by clicking the Enable Document Capture button; after you do and when you click the Click Me! button, all you'll see is an alert box with the message Captured by the document. :

(Listing 15-13.html on the web site)
 <HTML>      <HEAD>          <TITLE>Capturing and releasing events in NS4</TITLE>          <SCRIPT LANGUAGE="JavaScript">              <!--  document.onclick=click   function capture()   {   document.captureEvents(Event.CLICK)   }   function click(e)   {   if (e.target.type == "button") {   alert("Captured by the document.")   document.releaseEvents(Event.CLICK)   }   }  //-->          </SCRIPT>      </HEAD>      <BODY>          <H1>Capturing and releasing events in NS4</H1>          <FORM>              <INPUT TYPE="BUTTON" ONCLICK="capture()" VALUE="Enable Document Capture">              <BR>              <INPUT TYPE="BUTTON" VALUE="Click Me!" ONCLICK="alert('Button saw the event. graphics/ccc.gif ')">          </FORM>      </BODY>  </HTML> 

In this way, you can capture events that start at the top of the object hierarchy before they can move down to their intended target. To stop capturing events, you use the releaseCapture method.



Inside Javascript
Inside JavaScript
ISBN: 0735712859
EAN: 2147483647
Year: 2005
Pages: 492
Authors: Steve Holzner

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net