Partager via


attachNotification Method

 

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

Syntax

behavior.attachNotification (fpNotify)

Values

  • 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:

  • "contentReady"   There has been a change to the content of the element to which the behavior is attached. This is fired as soon as the closing tag of the element is parsed, as well as when a script sets the DHTML innerHTML property of the element. A behavior can use this notification to retrieve the content of the element it is applied to.

  • "documentReady"   The browser has finished parsing the document. Any modifications or initializations that need to be made to the content can take place at this point.

    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>

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>

See Also

<event> Element