MAMA: Event-handler attributes
By Brian Wilson
Index:
- Introduction
- Mouse events
- Key events
- Page-loading events
- Forms-related events
- Other popular event handlers
Introduction
Event-handler attributes are a non-portable way to directly associate Script
code with a specific element via an action on that element. Event handlers
were detected ~2/3 of all the URLs using Script, so a closer look at the many
attributes this encompasses is useful in our discussion. MAMA's global list
of markup attributes revealed 52 unique event
handler attribute names, but to simplify things we will cover only the 24 that
were detected more than 500 times each in MAMA's URLs. This attribute list
documents over 300 element/event handler combinations; however, since the lower
bound for the entire list was 50, there are surely many more element/event
combinations that could be mined from MAMA.
Event handler | Frequency | |
Event handler | Frequency | | Event handler | Frequency |
Onmouseover | 1,051,631 | Onmousedown | 57,049 | Onselectstart | 8,643 |
Onmouseout | 998,854 | Onmouseup | 41,497 | Onmousemove | 7,173 |
Onload | 772,567 | Onunload | 34,612 | Onbeforeunload | 6,751 |
Onclick | 684,117 | Onkeypress | 28,601 | Ondragstart | 6,510 |
Onfocus | 197,235 | Onresize | 17,950 | Onerror | 4,892 |
Onchange | 163,476 | Oncontextmenu | 15,684 | Onscroll | 3,523 |
Onsubmit | 152,286 | Onkeydown | 14,518 | Ondblclick | 2,416 |
Onblur | 88,175 | Onkeyup | 9,874 | Oncopy | 720 |
Event handlers that occurred below the 500 threshold included the following attributes:
Onabort
, Onactivate
,
Onafterprint
, Onbeforeactivate
,
Onbeforecopy
, Onbeforeprint
,
Oncontext
, Ondrag
,
Ondraggesture
, Ondrop
,
Onenter
, Onfocusin
,
Onfocusout
, Onhelp
,
Oninput
, Onpropertychange
,
Onstart
, Onmouseenter
,
Onmouseleave
, Onmouseoff
,
Onmousewheel
, Onmove
,
Onpaste
, Onreset
,
Onselect
, Onsrc
,
Onstart
.
Mouse events
Except for a few cases, the mouse-event-handler attributes
(Onmouseover
, Onmouseout
,
Onmousedown
, Onmouseup
,
Onmousemove
, Onclick
,
Ondblclick
and Oncontextmenu
)
show their greatest affinity toward the A element. The popularity and order
of elements for Onmouseover
and Onmouseout
is quite similar, although Onmouseover
enjoys a
slight lead in every single case. The same can be said of another event pair—Onmousedown
is slightly more popular in (almost) every
element case compared to the Onmouseup
attribute.
The mouse event handlers were found in 1,394,783 of the URLs that MAMA
analyzed, but their analogs in the DOM were only detected in 553,008 cases—the preference for the event handler version seems rather lopsided.
Onmouseover
attribute
ELEMENT | Frequency | |
Element | Frequency | | Element | Frequency |
A | 829,262 | INPUT | 18,389 | BODY | 3,728 |
IMG | 118,796 | TR | 15,721 | FONT | 3,595 |
TD | 81,709 | TABLE | 10,550 | LAYER | 3,034 |
DIV | 64,770 | SPAN | 9,816 | UL | 2,597 |
AREA | 32,249 | LI | 6,403 | DT | 1,262 |
MARQUEE | 29,455 | P | 5,807 | DD | 841 |
Onmouseout
attribute
ELEMENT | Frequency | |
Element | Frequency | | Element | Frequency |
A | 781,567 | INPUT | 15,307 | FONT | 3,055 |
IMG | 107,916 | TR | 14,754 | LAYER | 2,980 |
TD | 77,063 | TABLE | 9,149 | UL | 2,422 |
DIV | 56,509 | SPAN | 8,643 | BODY | 1,379 |
MARQUEE | 29,633 | P | 5,385 | DD | 800 |
AREA | 27,535 | LI | 4,989 | DT | 514 |
Onmousedown
attribute
ELEMENT | Frequency | |
Element | Frequency | | Element | Frequency |
A | 23,664 | DIV | 3,030 | TABLE | 783 |
IMG | 23,161 | INPUT | 1,822 | BODY | 644 |
TD | 3,111 | AREA | 976 | | |
Onmouseup
attribute
ELEMENT | Frequency | |
Element | Frequency | | Element | Frequency |
IMG | 19,636 | DIV | 979 | INPUT | 787 |
A | 16,359 | BODY | 851 | TABLE | 592 |
TD | 1,229 | AREA | 803 | | |
Onmousemove
attribute
ELEMENT | Frequency | | Element | Frequency |
BODY | 3,221 | DIV | 783 |
A | 1,619 | IMG | 705 |
Onclick
attribute
ELEMENT | Frequency | |
Element | Frequency | | Element | Frequency |
A | 492,092 | TABLE | 5,866 | TH | 581 |
INPUT | 156,871 | BODY | 4,958 | B | 562 |
IMG | 56,007 | BUTTON | 3,857 | FORM | 535 |
TD | 42,654 | P | 2,946 | STRONG | 527 |
DIV | 34,524 | LI | 2,936 | H1 | 517 |
AREA | 21,503 | SELECT | 2,604 | TEXTAREA | 503 |
SPAN | 14,771 | FONT | 2,240 | | |
TR | 6,972 | DT | 661 | | |
Ondblclick
attribute
Oncontextmenu
attribute
ELEMENT | Frequency |
BODY | 9,555 |
IMG | 5,114 |
Key events
The Key events (Onkeypress
, Onkeydown
,
Onkeyup
) register actions taken using a keyboard. 48,825 of
MAMA's URLs used at least one of these event attributes. MAMA's Script tokenization effort revealed
that these events are mentioned directly in Script 68,656 times, so authors seem
less inclined to use the event handler versions in this case. These event handlers
are primarily used with the INPUT
element, but authors
use them sporadically with other elements as well. Other than the INPUT
element, the different types of key activation (up/down/press) do not show any
significant use patterns—the frequency rates and the elements they apply to seem
to be rather haphazard.
ELEMENT[Event] | Frequency | | ELEMENT[Event] | Frequency |
INPUT [Onkeypress ] | 16,912 | BODY [Onkeypress ] | 688 |
INPUT [Onkeydown ] | 11,277 | TD [Onkeyup ] | 1,813 |
INPUT [Onkeyup ] | 5,740 | TR [Onkeyup ] | 1,787 |
A [Onkeypress ] | 7,064 | FORM [Onkeypress ] | 953 |
DIV [Onkeypress ] | 3,105 | TEXTAREA [Onkeyup ] | 892 |
BODY [Onkeydown ] | 1,538 | IMG [Onkeypress ] | 568 |
Page-loading events
These events (Onload
, Onunload
and Onbeforeunload
) trigger at the beginning or end of
the page load process. Script logic often relies on having all of a page and its
resources parsed and available to the script, so the overwhelming popularity of
the Onload
event use is understandable (especially its
dominance on the BODY
element). Authors seem to prefer
the event-handler version of detecting the page loading events over using the
equivalent DOM event-detection mechanism—the event-handler version was detected
in 782,776 cases whereas MAMA detected only 699,741 cases using the DOM
onload
and onunload
tokens.
The overlap between the event handlers and DOM version was fairly low; only 138,585
cases used both. This means that 1,343,932 cases tried to do something with the
onload event—over half of all URLs using Script in some form!
ELEMENT[Event] | Frequency | | ELEMENT[Event] | Frequency | |
ELEMENT[Event] | Frequency |
BODY [Onload ] | 741,946 | IMG [Onload ] | 46,870 |
IFRAME [Onload ] | 1,855 |
BODY [Onunload ] | 33,622 | FRAMESET [Onload ] | 7,650 |
LAYER [Onload ] | 1,417 |
BODY [Onbeforeunload ] | 5,921 | FRAMESET [Onload ] | 930 |
TABLE [Onload ] | 633 |
While some of these event handlers are also used by other elements (like
hyperlinks and BODY
), these attributes see their
primary usage with Forms-related elements. For the events that share element
usage (Blur and Focus), the Focus attribute always seems to have considerably
higher rates. Authors show a strong preference in using the Onchange
event handler with the SELECT
element (almost 25
times as often as INPUT
), even though the use cases
for both are equally interesting. Overall, these attributes were used in 430,964
URLs. The DOM methods of specifying these same events were only used in 107,824
URLs, which suggests that authors prefer to use the event-handler versions for these events.
Change, Focus, and Blur events
ELEMENT[Event] | Frequency | | ELEMENT[Event] | Frequency | |
ELEMENT[Event] | Frequency |
INPUT [Onfocus ] | 146,043 | AREA [Onfocus ] | 4,193 |
SELECT [Onblur ] | 694 |
INPUT [Onblur ] | 79,253 | TEXTAREA [Onfocus ] | 2,315 |
IMG [Onfocus ] | 951 |
A [Onfocus ] | 50,809 | TEXTAREA [Onblur ] | 1,511 |
BODY [Onfocus ] | 924 |
A [Onblur ] | 7,516 | SELECT [Onfocus ] | 1,329 |
TD [Onfocus ] | 650 |
ELEMENT | Frequency |
SELECT | 158,761 |
INPUT | 6,636 |
Onsubmit
attribute
The Onsubmit
event handler clocks in with very high
numbers on the FORM
element, and even has a respectable
number of URLs using the attribute improperly with the INPUT
element. This illegal INPUT
[Onsubmit
]
usage registers considerably higher than the miserable showing (only 200 URLs) of the
Onreset
event handler in its valid pairing with the
FORM
element.
ELEMENT | Frequency |
FORM | 151,699 |
INPUT | 804 |
Other popular event handlers
These are the other element/event-handler combinations that registered above
our arbitrary usage threshold of 500 URL cases. Most of these tend to be used
with the BODY
element. Applying an event handler to
the BODY
element usually indicates an author's desire
to have the event be global in scope, so this prominence is expected.
ELEMENT[Event] | Frequency | | ELEMENT[Event] | Frequency |
BODY [Onresize ] | 17,453 | BODY [Oncopy ] | 619 |
BODY [Onselectstart ] | 6,830 | IMG [Onerror ] | 4,708 |
BODY [Ondragstart ] | 5,671 | DIV [Onselectstart ] | 818 |
BODY [Onscroll ] | 3,363 | FRAMESET [Onresize ] | 520 |
This article is licensed under a Creative Commons Attribution, Non Commercial - Share Alike 2.5 license.
Comments
The forum archive of this article is still available on My Opera.