[Greasemonkey] GM 0.62 and Mint stats tracker: Component not
available error
chris feldmann
cfeldmann at gmail.com
Fri Oct 7 12:11:12 EDT 2005
> I thought I saw a note about this on Jeremy's wiki, but I can't find
> it just now. Maybe someone else can (or maybe I'll just add it again):
> http://dunck.us/collab/GreaseMonkeyUserScripts
>
Found it. There's no named anchor, so for reference, cut and pasted:
Setting elementWrapper.onclick = 'javascript code' does not work;
neither does setting elementWrapper.onclick = functionRef. "Component
is not available" is the typical error seen. Instead, you need to use
addEventListener and call event.preventDefault() inside your event
handler if you want to prevent the event from bubbling, example:
function my_click_handler(event) { ...; event.preventDefault(); }
var elmLink = document.createElement('a');
elmLink.addEventListener('click', my_click_handler, true);
This applies to any element, not just new ones you create, and any
event handler, not just onclick. If you are defining an onkeypress
handler for an input element you get by ID, this is the only variation
that works in Deer Park:
function my_keypress_handler(event) { ...; event.preventDefault(); }
var elmInput = document.getElementById('foo');
elmInput.addEventListener('keypress', my_keypress_handler, true);
More information about the Greasemonkey
mailing list