ChartDirector 6.0 (Ruby Edition)

JsChartViewer.addEventListener


Usage

addEventListener(obj, evt, func[, useCapture])

Description

A utility to attach an event handler to a Javascript event.

A Javascript event refers to Javascript events generated by the browser (as opposed to JsChartViewer events). An example is the "onload" event of the <body> tag.

The classical way to attach an event handler to a Javascript event is to use an attribute. For example, the "onload" attribute can be used to attach a handler to the "onload" event. The disadvantage of this method is that only one event handler can be attached. It becomes difficult to manage if multiple scripts all want to programmatically attach event handlers to the same event of the same object.

Modern browsers have special methods that allow multiple event handlers to be attached to the same event of the same object. However, the methods are different for different browsers. Some browsers use the addEventListener method, while some browsers use the attachEvent method.

JsChartViewer.addEventListener is a utility method that calls the target object's addEventListener method if the method exists, or the attachEvent method if it does not exist. Using this method an avoid writing different code to handle different browsers.

Note: This is a static method (class method). It should be accessed as JsChartViewer.addEventListener, not objName.addEventListener.

Arguments

ArgumentDefaultDescription
obj(Mandatory)The object to which the event handler is attached to.
evt(Mandatory)The name of the event, according to the Javascript addEventListener method. In this method, there is no "on" in front of the event name. For example, the event for the "onload" attribute should simply be called "load", not "onload".
func(Mandatory)A Javascript function that handles the event.
useCapture(Optional)The useCapture flag as used in the Javascript addEventListener method.

Return Value

None