javascript - greasemonkey adding onclick event to button -
I am attaching the onclick event to the dynamically created button, but the event is not firing
var ind = location.href.indexOf ('http://www.example.com/'); Function init () {warning ('h'); } If (IND! = -1) {var elem = document.createElement ("Input"); Elem.id = 'btnGumb'; Elem.value = 'Select the check box'; Elem.type = 'Button'; Elem.style.position = 'fixed'; Elem.style.left = '0px'; Elem.style.top = '0px'; // This elem.setAttribute ('onclick', 'init ();') is not working; // but being alert: elem.setAttribute ('onclick', 'alert ("h");'); Document.body.appendChild (ELEM); }
elem.addEventListener ('click', init, false);
Your init
function content is not defined on the page window, so you can not set the function name as a string.
Comments
Post a Comment