Microsoft® Windows® Script Component
attachNotification Method
 Behavior Handler Reference

See Also


Binds a function in the script component to a notification message sent from the host.

Syntax

behavior.attachNotification (fpNotify)

Parameters

behavior
The ID of the <implements> element used to implement the Behavior interface.

Note   By default, the properties and methods exposed by the Behavior handler are automatically added to the global script namespace and can be accessed without referencing the Behavior handler ID. In this case, instead of using Behavior.attachNotification as shown in the syntax, the method can be used in script simply as attachNotification. For more details, see the <implements> element.

fpNotify
The name of the function to bind to the notification.

Remarks

Currently, the host can call the specified function with the following notifications:

Note The attachNotification method does not notify the script component of standard events that occur in the document, window, or any element on the page. The recommended way to receive notifications on this type of event is by using the DHTML achEvent method.

When dealing with changes to an element's DHTML style property, such as setting its visibility, changing colors, or changing fonts, it is recommended that the changes be made inline in the script component's <script> element, as shown in the following script component fragment. Making the change in the documentReady notification clause can cause slight flashing.

Note   A CDATA section is required to make the script in the <script> element opaque. For details, see Script Component Files and XML Conformance.

<implements type="Behavior"/>
<script language="JScript">
<![CDATA[
   style.color = "green";
   style.letterSpacing = 5;
]]>
</script>

Example

The example below demonstrates how a function could be set up to trap notifications and process them as appropriate.

Note   A CDATA section is required to make the script in the <script> element opaque. For details, see Script Component Files and XML Conformance.

<?XML version="1.0"?>
<component>
<implements type="Behavior">
   <event name="onResultChange"/>
</implements>

<script language="JScript">
<![CDATA[
   attachNotification (onNotification);
   function onNotification (sNotification){
      if (sNotification == "contentReady"){
         // Contents of element have changed.
      }
      else if (sNotification == "documentReady"){
         // Host has finished parsing element.
      }
      window.status = sNotification;
   }
]]>
</script>
</component>