js; event cascading; onmousedown etc

hi peoples,
Another question that doesn't exist according to the books.
This is one problem expressed in two fashions.

Mouse events are happening twice, how to I make the first hook eat the event?
specifically:
[[1]]
<a href="./somewhere.html" onmousedown="goSomeWhere();" ... >Go somewhere</a>

where goSomeWhere() is a wrapper function, that moves the window to ./somewhere.html, and does some user interface thingies.   The goSomeWhere() *has* to do the page move, as it applies the changes to the newly loaded page.
The plain href is required for people with Javascript disabled.

[[2]]
<span id="span1" onmousedown="anotherWrapper('a1');" ... > <a id="a1" onmousedown="goSomeWhere();"> ...

It is claimed that many users lack accuracy with mice, so I put the spans round the links to increase the target area, for them to hit.   My pages are automatically generated, and anotherWrapper() is a utility function that works out what the inner elements are, and invokes them.   If the inner element has a onmousedown hook, it runs it; if there is a href is jumps down it.
The problem is, if you click on the link both goSomeWhere() and anotherWrapper() are called.

potentail solutions:
for 1: goSomeWhere deletes the href attribute, but this seems dangerous.
         I just tried making onmousedown hook into onclick, but this crashes moz

for 2: add a variable, to act as a mutex, so only one function happens.

There must be a better way of doing this.   Both the functions return true, which is supposed to suppress further activity, but it ain't.

this is some what long post
Owen

LVL 1
DeeperDarkerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ZontarCommented:
Two comments.

1. Why not just just make the links bigger with CSS? You can increase their size and/or margins and/or padding just like you can with any other element.

2. Trapping onmousedown as opposed to onclick would annoy the hell out of me if I were using your site.

You might want to look at attachEvent() and addEventListener() and how to cancel event-bubbling once an event's been noticed.

0
DeeperDarkerAuthor Commented:
Z: 2. Trapping onmousedown as opposed to onclick would annoy the hell out of me if I were using your site.

how could you tell?
unless you tried drag-click.
0
makcCommented:
>> Mouse events are happening twice, how to I make the first hook eat the event?
event.cancelBubble = true or something, I guess
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

ZontarCommented:
> unless you tried drag-click.

Exactly! I make frequent use of Mozilla's ability to drag a link to the tabbar in order to open a link in a new tab. This would also interfere with users wishing to right-click/ctrl-click/click-hold to get a context menu for opening the link in a new browser window or other legitimate pruposes.
0
DeeperDarkerAuthor Commented:
I rebuilt the pages with the larger anchor element (with CSS), as Zontar's  suggestion.
This cancels point 2.

The onmousedown is random paranoia, about wanting my code to run before whatever the browser does by default.
During the rebuild I moved the onmousedown to onclick

makC: [event.cancelBubble = true] what browsers support this?   I'm posting this to you (rather than reading), as the different browsers have different event models.  

Does anyone know whether onclick will suppress the traditional href on an anchor?   (I mean in a reliable consistent fashion)
0
ZontarCommented:
You could use some JavaScript to rewrite the href atttributes:

<script type="text/javascript">
window.onload = rewriteHrefs;

function rewriteHrefs()
{
  for(var i = 0; i < document.links.length; i++)
  {
    document.links[i].href = "javascript:goSomewheret(\"" + document.links[i].href + "\");";
  }
}
</script>

I pulled a similar stunt a couple of years ago... you wouldn't even need the onclick handlers, perhaps?

If you only want to rewrite certain links, give them a class attribute and test document.links[i].className.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DeeperDarkerAuthor Commented:
Actually its just one link, that flips between different indexes.

In opera the "open in new window" gesture works in conjunction to onclick
doesn't Moz have this level of thoroughness?

will apply this.
points for you Zontar ;-)
0
ZontarCommented:
You can get a mouse-gestures add-on for Moz, but I could never warm to them in Opera, so I've not tried it. Could be the fault of our cats bumping my elbow all the time.

Ta. :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.