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.
© 2021 Advanced Software Engineering Limited. All rights reserved.