[Javascript] Bubbling and canceling events

Peter Brunone peter at brunone.com
Tue Jun 10 22:29:06 CDT 2008


Hi Philip,

    Does this misfire in all browsers, or just in Firefox and family?

    It is my understanding that in order to use the (Mozilla only) event parameter in your function, you have to include it as a parameter in your function definition.  So, to draw from your example below, if you are referring to this event as "e", then you need to specify the parameter as such like this:

function printCard (e) 

    No parameter is necessary when you call the function from the event handler, and IE won't see it; only Mozilla will.

HTH,

Peter

----------------------------------------

From: Philip Thompson philthathril at gmail.com

Hi all.

In the application I'm working on, I keep coming back to this similar 
problem. I'll just show you here...

Johnny Appleseed	 12/3/1981	 Print Card	 

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 

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