Reputation: 10348
I am working in a browser extension. I am putting some icons next to links in google search pages. These icons trigger some actions and I need stop bubble events after user clicks on it. In resume, parent div tags must not know about clicks on these icons.
Next code allow stop bubbling events in all browsers:
if (event.cancelBubble) {
event.cancelBubble = true;
}
if (event.returnValue) {
event.returnValue = false;
}
if (event.stopPropagation) {
event.stopPropagation();
}
if (event.preventDefault) {
event.preventDefault();
}
In Firefox works well but in this context not works in IE (version 8 at least). Any idea about it?
Upvotes: 1
Views: 2998
Reputation: 318518
if (event.cancelBubble) {
event.cancelBubble = true;
}
This doesn't make sense. It only sets it to true
if it already evaluates to true (in a boolean context). Get rid of the if clause (i.e. always set it unconditionally); setting a non-existant value usally doesn't do any harm (unless you are setting it on a host object which has an ugly implementation)
Upvotes: 2
Reputation: 4327
or try setting it to false, if u use true, the event will fire the code that comes after the event has been fired, when an event has a boolean, it could sometimes mean that u have the freedom to control that event, if u say true, the event may execute other function(s). when saying false the event will not execute other functions, but that only depends on how that function.
coder made his function/code.
but in simple words "To handle or to raise the bubbled event, a control must override the OnBubbleEvent method.", and thats where u do the opposite dont override if u did.
if u havent read this yet http://msdn.microsoft.com/en-us/library/aa719644(v=vs.71).aspx and like i said do the opposite.
; )
Hope this helps u out a bit
Laterss!
Upvotes: 0