MAMA: Event-handler attributes

By Brian Wilson

Index:

  1. Introduction
  2. Mouse events
  3. Key events
  4. Page-loading events
  5. Forms-related events
  6. 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.

Fig 1-1: Usage of event-handler attributes
Event handlerFrequency  Event handlerFrequency Event handlerFrequency
Onmouseover1,051,631Onmousedown57,049Onselectstart8,643
Onmouseout998,854Onmouseup41,497Onmousemove7,173
Onload772,567Onunload34,612Onbeforeunload6,751
Onclick684,117Onkeypress28,601Ondragstart6,510
Onfocus197,235Onresize17,950Onerror4,892
Onchange163,476Oncontextmenu15,684Onscroll3,523
Onsubmit152,286Onkeydown14,518Ondblclick2,416
Onblur88,175Onkeyup9,874Oncopy720

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

Fig 2-1: Elements using the Onmouseover attribute
ELEMENTFrequency  ElementFrequency ElementFrequency
A829,262INPUT18,389BODY3,728
IMG118,796TR15,721FONT3,595
TD81,709TABLE10,550LAYER3,034
DIV64,770SPAN9,816UL2,597
AREA32,249LI6,403DT1,262
MARQUEE29,455P5,807DD841

Onmouseout attribute

Fig 2-2: Elements using the Onmouseout attribute
ELEMENTFrequency  ElementFrequency ElementFrequency
A781,567INPUT15,307FONT3,055
IMG107,916TR14,754LAYER2,980
TD77,063TABLE9,149UL2,422
DIV56,509SPAN8,643BODY1,379
MARQUEE29,633P5,385DD800
AREA27,535LI4,989DT514

Onmousedown attribute

Fig 2-3: Elements using the Onmousedown attribute
ELEMENTFrequency  ElementFrequency ElementFrequency
A23,664DIV3,030TABLE783
IMG23,161INPUT1,822BODY644
TD3,111AREA976  

Onmouseup attribute

Fig 2-4: Elements using the Onmouseup attribute
ELEMENTFrequency  ElementFrequency ElementFrequency
IMG19,636DIV979INPUT787
A16,359BODY851TABLE592
TD1,229AREA803  

Onmousemove attribute

Fig 2-5: Elements using the Onmousemove attribute
ELEMENTFrequency ElementFrequency
BODY3,221DIV783
A1,619IMG705

Onclick attribute

Fig 2-6: Elements using the Onclick attribute
ELEMENTFrequency  ElementFrequency ElementFrequency
A492,092TABLE5,866TH581
INPUT156,871BODY4,958B562
IMG56,007BUTTON3,857FORM535
TD42,654P2,946STRONG527
DIV34,524LI2,936H1517
AREA21,503SELECT2,604TEXTAREA503
SPAN14,771FONT2,240  
TR6,972DT661  

Ondblclick attribute

Fig 2-7: Elements using the Ondblclick attribute
ELEMENTFrequency
A507

Oncontextmenu attribute

Fig 2-8: Elements using the Oncontextmenu attribute
ELEMENTFrequency
BODY9,555
IMG5,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.

Fig 3-1: Elements using "Key" Event Handlers
ELEMENT[Event]Frequency ELEMENT[Event]Frequency
INPUT[Onkeypress]16,912BODY[Onkeypress]688
INPUT[Onkeydown]11,277TD[Onkeyup]1,813
INPUT[Onkeyup]5,740TR[Onkeyup]1,787
A[Onkeypress]7,064FORM[Onkeypress]953
DIV[Onkeypress]3,105TEXTAREA[Onkeyup]892
BODY[Onkeydown]1,538IMG[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!

Fig 4-1: Elements using "Load" Event Handlers
ELEMENT[Event]Frequency ELEMENT[Event]Frequency  ELEMENT[Event]Frequency
BODY[Onload]741,946IMG[Onload]46,870 IFRAME[Onload]1,855
BODY[Onunload]33,622FRAMESET[Onload]7,650 LAYER[Onload]1,417
BODY[Onbeforeunload]5,921FRAMESET[Onload]930 TABLE[Onload]633

Forms-related events

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

Fig 5-1: Elements using Focus/Blur Event Handlers
ELEMENT[Event]Frequency ELEMENT[Event]Frequency  ELEMENT[Event]Frequency
INPUT[Onfocus]146,043AREA[Onfocus]4,193 SELECT[Onblur]694
INPUT[Onblur]79,253TEXTAREA[Onfocus]2,315 IMG[Onfocus]951
A[Onfocus]50,809TEXTAREA[Onblur]1,511 BODY[Onfocus]924
A[Onblur]7,516SELECT[Onfocus]1,329 TD[Onfocus]650
Fig 5-2: Elements using the Onchange attribute
ELEMENTFrequency
SELECT158,761
INPUT6,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.

Fig 5-3: Elements using the Onsubmit attribute
ELEMENTFrequency
FORM151,699
INPUT804

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.

Fig 6-1: Elements using various Event Handler attributes
ELEMENT[Event]Frequency ELEMENT[Event]Frequency
BODY[Onresize]17,453BODY[Oncopy]619
BODY[Onselectstart]6,830IMG[Onerror]4,708
BODY[Ondragstart]5,671DIV[Onselectstart]818
BODY[Onscroll]3,363FRAMESET[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.

No new comments accepted.