The attachEvent Method


The attachEvent Method

You can use the attachEvent method to attach an event handler to an event in the Internet Explorer. This method returns true if the event handler was connected successfully. You can see the support for this method in Table 6.9.

Table 6.9. The attachEvent Method

Method

NS2

NS3

NS4

NS6

IE3a

IE3b

IE4

IE5

IE5.5

IE6

attachEvent ( event , handlerFunction )

             

x

x

x

 

Returns: Boolean

You pass this method the event to handle (as a string) and the handler function. We've already seen an example using the attachEvent method in the beginning of this chapter; in that example, I attached an event handler to a button's onclick event:

 <HTML>      <HEAD>          <TITLE>Using the attachEvent Method</TITLE>      </HEAD>      <BODY>          <H1>Using the attachEvent Method</H1>          <FORM NAME="form1">              <INPUT TYPE="BUTTON" NAME="button1" VALUE="Click Me!">          </FORM>          <SCRIPT LANGUAGE="JavaScript">              <!--  document.form1.button1.attachEvent("onclick", alerter)   function alerter()   {   alert("You clicked the button!")   }  // -->          </SCRIPT>      </BODY>  </HTML> 


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