I've read that one must return false from an onclick handler attached
to an anchor if we wanted to prevent the browser from following the
href. In a greasemonkey script I'm hacking together with duct tape and
chicken wire the links that I'm creating follow the hrefs, killing the
associated action. To get around this, I'm assigning the URL which I
need in the logMe function to a made up attribute, rather than use
newlink.href as I do below.
In newlink below, my browser (Firefox) will follow the href despite my
returning false. What did I do wrong? Thanks
for (linkIndex = 0; linkIndex < doclinks.snapshotLength; linkIndex++)
{
var origlink = doclinks.snapshotItem(linkIndex);
if (origlink.href.match(myRE))
{
newlink = document.createElement('a');
newlink.innerHTML = " [ EXPAND ] ";
newlink.id = preamble + ":" + linkIndex;
newlink.href = origlink.href;
newlink.addEventListener('click', function(event){ logMe(event);
return false; }, false);
origlink.parentNode.insertBefore(newlink,origlink. nextSibling);
}
}