onbeforeactivate event | beforeactivate event
Occurs before an element becomes active.
The onbeforeactivate event is cancelable (unlike the onactivate event), therefore it is useful if you want to prevent the activation of an element.
Unfortunately it does not work for all elements and actions.
For details see the 'Actions that invoke the onbeforeactivate event' section.
To detect when an element loses its active state, use the onbeforedeactivate and ondeactivate events.
How to register:
In HTML:
In JavaScript:
<ELEMENT onbeforeactivate="handler"> |
In JavaScript:
object.onbeforeactivate = handler; | |||||||||||
object.addEventListener ("beforeactivate", handler, useCapture); |
| ||||||||||
object.attachEvent ("onbeforeactivate", handler); |
You can find the related objects in the Supported by objects section below.
The event object is accessible to all event handlers in all browsers.
The properties of the event object contain additional information about the current event.
To get further details about these properties and the possible event handler registration methods, please see the page for the event object.
For a complete list of events, see the page for Events in JavaScript. |
Basic information:
Bubbles | Yes |
Cancelable | Partially |
Event object | UIEvent |
Actions that invoke the onbeforeactivate event:
The onbeforeactivate event is not cancelable if it is triggered by the setActive or focus method.
If the onbeforeactivate event is triggered by the TAB key, then it is cancelable.
For other actions (clicking and pressing an access key) the onbeforeactivate event is partially cancelable.
It is not cancelable for editable elements and cancelable for others.
If you want to prevent a non-editable element from getting the focus in Internet Explorer, cancel the onbeforeactivate event.
For a cross-browser solution and an arbitrary element, set the disabled property of the element to true.
See the examples for details.
The order of events related to the onbeforeactivate event:
Action | Event order |
---|---|
Any action that invokes the onbeforeactivate event. |
|
Example HTML code 1:
This example cancels the onbeforeactivate event for a button element in Internet Explorer. For a cross-browser solution, please see the next example.:
|
||||
<head> <script type="text/javascript"> function CancelActivation (event) { // prevent the propagation of the current event if (event.stopPropagation) { event.stopPropagation (); } else { event.cancelBubble = true; } // cancel the current event return false; } </script> </head> <body> The second button cannot be activated by the user.<br /> Try to click on it or use the TAB key to navigate through the buttons or press the ALT+2 access key! <br /><br /> <button accesskey="1">ALT + 1</button> <button accesskey="2" onbeforeactivate="return CancelActivation (event);">ALT + 2</button> <button accesskey="3">ALT + 3</button> </body> |
||||
|
||||
Did you find this example helpful?
|
Example HTML code 2:
This example implements a cross-browser solution for the previous one:
|
||||
The second button cannot be activated by the user.<br /> Try to click on it or use the TAB key to navigate through the buttons or press the ALT+2 access key! <br /><br /> <button accesskey="1">ALT + 1</button> <button accesskey="2" disabled="disabled">ALT + 2</button> <button accesskey="3">ALT + 3</button> |
||||
|
||||
Did you find this example helpful?
|
Supported by objects:
document
HTML elements:
a, abbr, acronym, address, applet, area, b, bdo, big, blockquote, body, button, caption, center, cite, code, dd, del, dfn, dir, div, dl, dt, em, embed, fieldset, font, form, frame, frameset, h1, h2, h3, h4, h5, h6, hr, html, i, iframe, img, input:button, input:checkbox, input:file, input:image, input:password, input:radio, input:reset, input:submit, input:text, ins, isindex, kbd, label, legend, li, listing, map, marquee, menu, noframes, object, ol, p, plaintext, pre, q, rt, ruby, s, samp, select, small, span, strike, strong, sub, sup, table, tbody, td, textarea, tfoot, th, thead, tr, tt, u, ul, var, xmp
Related pages:
External links:
User Contributed Comments