Hi,

One of the few good things about those old-style handlers is that
they're attributes, so finding the links is easy:

var hookedlinks = $$('a[onclick]');

Then if your goal is to remove the handler:

var n;
for (n = hookedlinks.length - 1; n >= 0; --n) {
    hookedlinks[n].onclick = null;
}

Or you can have more fun, I wrote this up a while back to convert DOM0
handlers into modern ones and optionally put some pre-condition logic
in place prior to firing the DOM0 handler:

* * * * (also at http://pastie.org/573599)
function wrapDom0Handler(elm, evtname) {
    var propname, dom0handler;

    // Grab the current DOM0 handler for the event
    propname = "on" + evtname;
    dom0handler = elm[propname];

    // Clear it
    elm[propname] = null;

    // Hook up your handler
    elm.observe(evtname, function(event) {
        var rv;

        alert("TODO: Your optional precondition logic goes here");

        // Chain to the DOM0 handler, if any
        if (Object.isString(dom0handler)) {
            rv = eval(dom0handler);
        }
        else if (Object.isFunction(dom0handler)) {
            rv = dom0handler.call(elm, event);
        }
        if (!Object.isUndefined(rv) && !rv) {
            // Handler returned something falsey, cancel
            event.stop();
        }
    });
}
* * * *

HTH,
--
T.J. Crowder
tj / crowder software / com
Independent Software Engineer, consulting services available

On Aug 4, 11:21 pm, Hipnotik <[email protected]> wrote:
> Hi
> I have observer set for the whole document to catch click events on
> links (a href) and prevent default action (open page from href,
> event.stop). It works correct, but ... now I have onclick event
> defined inside of each a-herf element and I need to catch/prevent this
> event too. How to do that? I'm hope it's quite clear ;)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to