Disable tr onclick event...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • SomeGei

    Disable tr onclick event...

    Hey guys....

    i have a really big table... and the <tr> tags have onclick/onmouseover
    events that highlight a row when you drag your mouse over it, and open a
    popup window when you click anywhere in the row...

    if i however have some text in the row that has an href link attached to it,
    when i click on the link it will go to the href url AND open the popup
    window...

    is there any way to stop the popup window from opening when i click a
    certain link within a row?


  • Michael Winter

    #2
    Re: Disable tr onclick event...

    On Sun, 29 Aug 2004 17:27:32 GMT, SomeGei <some@gei.com > wrote:
    [color=blue]
    > i have a really big table... and the <tr> tags have onclick/onmouseover
    > events that highlight a row when you drag your mouse over it, and open a
    > popup window when you click anywhere in the row...
    >
    > if i however have some text in the row that has an href link attached to
    > it, when i click on the link it will go to the href url AND open the
    > popup window...
    >
    > is there any way to stop the popup window from opening when i click a
    > certain link within a row?[/color]

    Yes, but the approach depends on your environment. If you only care about
    recent browsers, you can use the DOM (Document Object Model) to stop the
    event propagating up the document tree. However, if you need to support
    older browsers, it becomes much less elegant.

    New browsers:

    <a ... onclick="stopBu bble(event);">

    function stopBubble(e) {
    if(e.stopPropag ation) {e.stopPropagat ion();}
    else {e.cancelBubble = true;}
    }

    See? Simple. :)

    Old browsers:

    <tr ... onclick="myFunc tion(event);">

    <!-- Notice the difference in the call! -->

    /* This is your pop-up code. */
    function myFunction(e) {
    var l = document.links,
    i = l.length,
    t = e.target || e.srcElement;

    /* Search to see if the target element
    * was a link. If it was, quit. */
    while(i--) {if(l[i] == t) {return;}}

    /* Rest of your function. */
    }

    By the way, I don't know how well the latter will work. It should be fine,
    but I haven't tested it.

    Good luck,
    Mike

    --
    Michael Winter
    Replace ".invalid" with ".uk" to reply by e-mail.

    Comment

    Working...