how to create listener java script

0 votes
35 views
asked Nov 26, 2012 in java script by anonymous
create custom javascript?

1 Answer

0 votes
answered Nov 26, 2012 by admin (8,115 points)

 

var evt = document.createEvent("Event");
evt.initEvent("myEvent",true,true);

// custom param
evt.foo = "bar";

//register
document.addEventListener("myEvent",myEventHandler,false);

//invoke
document.dispatchEvent(evt);

Here is the way to do it more locally, pinpointing listeners and publishers:http://www.kaizou.org/2010/03/generating-custom-javascript-events/

...