[Javascript] Bubbling and canceling events
Philip Thompson
philthathril at gmail.com
Tue Jun 10 17:38:00 CDT 2008
Hi all.
In the application I'm working on, I keep coming back to this similar
problem. I'll just show you here...
<table>
<tr onclick="goToUrl('viewuser.php?user_id=1');">
<td>Johnny Appleseed</td>
<td>12/3/1981</td>
<td><a href="javascript:printCard();">Print Card</a></td>
</tr>
<table>
Ok, let's say the user clicks on "Print Card". This is a javascript
function that performs some AJAX-related things in the background (in
this case, prints a card). After clicking to print, I wish nothing
more to happen - I wish to cancel the set of events that follow. In
this case, I want to cancel the call to the javascript function
goToUrl() as specified in the <tr> element - I do not want to visit
the view user page. To accomplish this, I attempted the following:
function printCard () {
if (!e) var e = window.event;
e.cancelBubble = true;
if (e.stopPropagation) e.stopPropagation();
//... do stuff here
}
However, it still redirects me!! Ahhhh! I can't handle it anymore. Is
there anyway to cancel the redirection/events? I would be greatly
appreciated if someone could shed some much-needed light.
Thanks in advance,
~Philip
Note: this is a somewhat simplified example of the real thing.
More information about the Javascript
mailing list