cancelBubble property
Sets or retrieves whether the current event should bubble up the hierarchy of event handlers.
Syntax
| JavaScript | |
|---|
Property values
Type: Boolean
VARIANT_FALSE (false)
-
Default. Bubbling is enabled, allowing the next event handler in the hierarchy to receive the event.
VARIANT_TRUE (true)
-
Bubbling is disabled for this event, preventing the next event handler in the hierarchy from receiving the event.
Remarks
Using this property to cancel bubbling for an event does not affect subsequent events.
Examples
This example cancels bubbling of the onclick event if it occurs in the img object when the user presses the SHIFT key. This prevents the event from bubbling up to the onclick event handler for the document.
<SCRIPT LANGUAGE="JScript">
function checkCancel()
{
if (window.event.shiftKey)
window.event.cancelBubble = true;
}
function showSrc()
{
if (window.event.srcElement.tagName == "IMG")
alert(window.event.srcElement.src);
}
</SCRIPT>
<BODY onclick="showSrc()">
<IMG onclick="checkCancel()" SRC="sample.png">
Send comments about this topic to Microsoft
Build date: 3/14/2012
Community Content
Mr. Raymond Kenneth Petry
limitation - Alt
Note that Alt-Enter/Alt-arrow cannot be canceled to override their default Windows/document action...
REMEDY #1: onbeforeunload='return "reason"' pops-up a document-prompt with-reason to leave-or-stay.
REMEDY #2. onkeydown=... if(altKey)if(keyCode>=37 && keyCode<=40) keyCode=0 ... return false.
REMEDY #1: onbeforeunload='return "reason"' pops-up a document-prompt with-reason to leave-or-stay.
REMEDY #2. onkeydown=... if(altKey)if(keyCode>=37 && keyCode<=40) keyCode=0 ... return false.