Talking about the default behavior of js stop event bubbling blocking browser of blocking hyperconnection
- 2021-07-18 06:24:07
- OfStack
In front-end development work, due to browser compatibility and other issues, we often use "stop event bubbling" and "prevent browser default behavior".
1. Stop event bubbling
JavaScript code
// If an event object is provided, this is 1 A mistake IE Browser
if ( e && e.stopPropagation )
// So it supports W3C Adj. stopPropagation() Method
e.stopPropagation();
else
// Otherwise, we need to use the IE The way to cancel the event bubbling
window.event.cancelBubble = true;
return false;
2. Block the browser's default behavior
JavaScript code
// If an event object is provided, this is 1 A mistake IE Browser
if ( e && e.preventDefault )
// Block default browser actions (W3C)
e.preventDefault();
else
//IE The way to prevent the default action of functionalists in
window.event.returnValue = false;
return false;