Programmer's Guide > Programming and Scripting Techniques > Events > Event Handlers > JavaScript
  
JavaScript
JavaScript uses the LiveConnect feature to connect to Java to create the DOM EventListener object to pass to addEventListener. The handler object associated with the EventListener is declared using object literal syntax.
function clickEvent(event)
{
var node = event.target;
var context = "";
while (node != null) {
if (node.nodeType == node.ELEMENT_NODE) {
context = "(" + node.nodeName + context;
}
node = node.parentNode;
}
Application.print(context + "\n");
event.stopPropagation();
}
var doc = Application.activeDocument;
// define an object with the required handleEvent method
var o = { handleEvent: clickEvent};
var listener = Packages.org.w3c.dom.events.EventListener(o);
doc.addEventListener("click", listener, true);