AquaLogic User Interaction Development Guide

     Previous Next  Open TOC in new window   View as PDF - New Window  Get Adobe Reader - New Window
Content starts here

Including JavaScript in Custom Adaptive Tags

To include JavaScript in a tag, use the AddJavaScript method inside the DisplayTag method.

For example:
HTMLScriptCollection scriptCollection = new HTMLScriptCollection(); 
HTMLScript script = new HTMLScript("text/javascript"); 
scriptCollection.AddInnerHTMLElement(script); 
script.AddInnerHTMLString("function myTest() { alert('test'); }"); 
AddJavascript(scriptCollection);
To include common JavaScript that can be shared between multiple instances of a tag (i.e. JavaScript that is displayed once per page, regardless of how many tags of a certain type there are), override the DisplaySharedJavascript method. DisplaySharedJavaScript is called automatically by the framework.
/** 
* Adds the PTIncluder object to the client.  This object is used for 
* retrieving JSComponent client classes from a page. 
*/ 
public HTMLScriptCollection DisplaySharedJavascript() 
{ 
HTMLScriptCollection result = new HTMLScriptCollection(); 
HTMLScript script = new HTMLScript("text/javascript"); 
result.AddInnerHTMLElement(script); script.SetSrc("/myjsfile.js"); 
return result; 
}
If there are errors in the tag and the JavaScript cannot be displayed properly, the tag should throw an XPException with an error message, and the tag framework will log the error and add the message and stack trace to the HTML as an HTML comment. The message contents will be HTML encoded before being added to the comment.
Note: JavaScript is not displayed in 508 mode for either method, since section 508 compliant browsers do not support JavaScript.

  Back to Top      Previous Next