SlideShare a Scribd company logo
1 of 95
Download to read offline
Hell is other browsers - Sartre




JavaScript Events
     Peter-Paul Koch (ppk)
    http://quirksmode.org
    http://twitter.com/ppk
     Yahoo!, 23 April 2009
http://quirksmode.org/dom/events/
Today's program:
- the key events
- the change event
- delegating the focus event
- first results of mobile event tests
The key events
keydown
  When a key is depressed.
  Repeats.
keypress


keyup
keydown
  When a key is depressed.
  Repeats.
keypress
  When a character key is
  depressed.
  Repeats.
keyup
keydown
  When a key is depressed.
  Repeats.
keypress
  When a character key is
  depressed.
  Repeats.
keyup
  When a key is released.
keydown and keypress
keydown only
Originally this theory was created
by Microsoft.

Safari has copied it.

It's the only theory; Firefox and
Opera just fire some random
events.
keydown
  When a key is depressed.
  Repeats.
keypress
  When a character key is
  depressed.
  Repeats.
Which key did my user press?

Two properties:
keyCode and charCode

Two bits of data:
- the key code
- the character code
Which key did my user press?

Obviously, having one property
contain one bit of data and the other
property the other

would be far too simple.
Which key did my user press?

keyCode

- onkeydown: key code
- onkeypress: character code
Which key did my user press?

charCode

- onkeydown: 0
- onkeypress: character code
Which key did my user press?

If you need the key:

el.onkeydown = function (e) {
  e = e || window.event;
  var realKey = e.keyCode;
}
Which key did my user press?

If you need the key:

el.onkeydown = function (e) {
  e = e || window.event;
  var realKey = e.keyCode;
}
Which key did my user press?

If you need the character:

el.onkeypress = function (e) {
  e = e || window.event;
  var char = e.keyCode || e.charCode;
}
Which key did my user press?

If you need the character:

el.onkeypress = function (e) {
  e = e || window.event;
  var char = e.keyCode || e.charCode;
}
How can I prevent the default action?

el.onkeydown = function (e) {
  e = e || window.event;
  var key = e.keyCode;
  if (key is incorrect) {
     // cancel default action
  }
}
How can I prevent the default action?

el.onkeydown = function (e) {
  e = e || window.event;
  var key = e.keyCode;
  if (key is incorrect) {
     // cancel default action
  }
}
change
The change event fires when the value
of a form field is changed.

This could be a very useful event; after
all it fires only when the user actually
changes something
instead of whenever he focuses on a
form field
- text fields
- select boxes
- checkboxes and radios
- text fields
- select boxes
- checkboxes and radios

              focus

              blur

No change event. The value hasn't
been modified.
- text fields
- select boxes
- checkboxes and radios

              focus

              blur

Change event. The value has been
modified.
- text fields
- select boxes
- checkboxes and radios

Mouse:



Click on select
- text fields
- select boxes
- checkboxes and radios

Mouse:



Click on new option
CHANGE
- text fields
- select boxes
- checkboxes and radios

Keyboard:

   focus


Focus on select
- text fields
- select boxes
- checkboxes and radios

Keyboard:

   focus    arrow


Arrow keys to move to other option
CHANGE
- text fields
- select boxes
- checkboxes and radios

        This is a
        BUG!
Arrow keys to move to other option
CHANGE
- text fields
- select boxes
- checkboxes and radios

Keyboard:

   focus    arrow


Arrow keys to move to other option
- text fields
- select boxes
- checkboxes and radios

Keyboard:

   focus     arrow        blur


Blur select box.
CHANGE
- text fields
- select boxes
- checkboxes and radios



  click

CHANGE when the checked property
changes.
- text fields
- select boxes
- checkboxes and radios



      click

...
- text fields
- select boxes
- checkboxes and radios



  click    blur

CHANGE when the element loses the
focus.
- text fields
- select boxes
- checkboxes and radios

         This is a
         BUG!
CHANGE when the element loses the
focus.
Event delegation
Event delegation
<ul>
  <li><a href=”#”>Multimedialize</a>
     <ul>
       <li><a href=”#”>Sound</a></li>
       <li><a href=”#”>Java applets</a></li>
     </ul></li>
  <li><a href=”#”>Ajaxify</a>
     <ul>
       <li><a href=”#”>Web 2.0</a></li>
       <li><a href=”#”>Web 3.0</a></li>
       <li><a href=”#”>Web 4.0b</a></li>
     </ul></li>
</ul>
Event delegation
Event delegation
  The event bubbles up to the <ul>
var dropdown = {
  anyway. (dropdown) {
   init: function
      dropdown.onmouseover = mouseOver;
      dropdown.onmouseout = mouseOut;
  So why not handle it at that level?
   }
}
Saves a lot of event handlers.
Event delegation

var dropdown = {
  init: function (dropdown) {
     dropdown.onmouseover = mouseOver;
     dropdown.onmouseout = mouseOut;
  }
}

Works in all browsers.
 Event delegation

But suppose someone doesn't use a
mouse at all,

but the keyboard

how does the menu fold out?
Device
independence
 Event delegation

var dropdown = {
  init: function (dropdown) {
     dropdown.onmouseover = this.mouseOver;
     dropdown.onmouseout = this.mouseOut;
  }
}
Event delegation

var dropdown = {
  init: function (dropdown) {
     dropdown.onmouseover = this.mouseOver;
     dropdown.onmouseout = this.mouseOut;
  }
}

Doesn't work without a mouse.
Event delegation

var dropdown = {
  init: function (dropdown) {
     dropdown.onmouseover = this.mouseOver;
     dropdown.onmouseout = this.mouseOut;
  }
}

We need events that tell us whether
the user enters or leaves a link.
focus and blur
Event delegation

var dropdown = {
  init: function (dropdown) {
     dropdown.onmouseover =
        dropdown.onfocus = this.mouseOver;
     dropdown.onmouseout =
        dropdown.onblur = this.mouseOut;
  }
}
Event delegation

var dropdown = {
  init: function (dropdown) {
     dropdown.onmouseover =
        dropdown.onfocus = this.mouseOver;
     dropdown.onmouseout =
        dropdown.onblur = this.mouseOut;
  }
}

Doesn't work.
Event delegation

var dropdown = {
  init: function (dropdown) {
     dropdown.onmouseover =
        dropdown.onfocus = this.mouseOver;
     dropdown.onmouseout =
        dropdown.onblur = this.mouseOut;
  }
}

Focus and blur don't bubble.
To bubble or not to bubble

Two kinds of events:
1) Mouse and key events
2) Interface events
To bubble or not to bubble

Two kinds of events:
1) Mouse and key events
2) Interface events

Fire when the user initiates a device-
specific action.
mouseover, mouseout, click, keydown,
keypress
To bubble or not to bubble

Two kinds of events:
1) Mouse and key events
2) Interface events

In general they bubble.
To bubble or not to bubble

Two kinds of events:
1) Mouse and key events
2) Interface events

Fire when a certain event takes place,
regardless of how it was initialised.
load, change, submit, focus, blur
To bubble or not to bubble

Two kinds of events:
1) Mouse and key events
2) Interface events

In general they don't bubble.
Event delegation

var dropdown = {
  init: function (dropdown) {
     dropdown.onmouseover = this.mouseOver;
     dropdown.onmouseout = this.mouseOut;
     var x = dropdown.getElementsByTagName('a');
     for (var i=0;i<x.length;i++) {
        x[i].onfocus = this.mouseOver;
        x[i].onblur = this.mouseOut;
     }
  }
}
Event delegation

So we're stuck with setting a focus and
blur event on every single link.

Or are we ... ?
Event delegation

Event capturing to the rescue.

Event capturing is the opposite of
event bubbling,
and it is supported in all W3C-
compliant browsers.
Event bubbling
addEventListener('click',fn,false)
Event capturing
addEventListener('click',fn,true)
Event delegation

The point is that if you capture a focus
event,

event handlers on the target element's
ancestors are executed.
Event bubbling
Focus on a:
a.onfocus executed
Event capturing
Focus on a: ul.onfocus, li.onfocus and
a.onfocus executed
 Event capturing and bubbling

Why this difference?

I have no idea.

Maybe it's time to have bubbling and
capturing act the same.
The current situation doesn't make
sense (though it's useful).
 Event delegation

var dropdown = {
  init: function (dropdown) {
     dropdown.onmouseover = this.mouseOver;
     dropdown.onmouseout = this.mouseOut;
  }
}
 Event delegation

var dropdown = {
  init: function (dropdown) {
     dropdown.onmouseover = this.mouseOver;
     dropdown.onmouseout = this.mouseOut;
     dropdown.addEventListener
        ('focus',this.mouseOver,true);
     dropdown.addEventListener
        ('blur',this.mouseOut,true);
  }
}
 Event delegation

var dropdown = {
  init: function (dropdown) {
     dropdown.onmouseover = this.mouseOver;
     dropdown.onmouseout = this.mouseOut;
     if (dropdown.addEventListener) {
         dropdown.addEventListener
           ('focus',this.mouseOver,true);
         dropdown.addEventListener
           ('blur',this.mouseOut,true);
     }
  }
}
 Event delegation
And what about IE?

It doesn't support addEventListener,
but fortunately it supports the
focusin and focusout events
which are like focus and blur,
except that they bubble.
 Event delegation

var dropdown = {
  init: function (dropdown) {
     dropdown.onmouseover = this.mouseOver;
     dropdown.onmouseout = this.mouseOut;
     if (dropdown.addEventListener) {
         dropdown.addEventListener
           ('focus',this.mouseOver,true);
         dropdown.addEventListener
           ('blur',this.mouseOut,true);
     }
  }
}
 Event delegation

var dropdown = {
  init: function (dropdown) {
     dropdown.onmouseover = this.mouseOver;
     dropdown.onmouseout = this.mouseOut;
     if (dropdown.addEventListener) {
         dropdown.addEventListener
           ('focus',this.mouseOver,true);
         dropdown.addEventListener
           ('blur',this.mouseOut,true);
     }
     dropdown.onfocusin = this.mouseOver;
     dropdown.onfocusout = this.mouseOut
  }
 Event delegation

   dropdown.onmouseover = this.mouseOver;
   dropdown.onmouseout = this.mouseOut;
   if (dropdown.addEventListener) {
       dropdown.addEventListener
         ('focus',this.mouseOver,true);
       dropdown.addEventListener
         ('blur',this.mouseOut,true);
   }
   dropdown.onfocusin = this.mouseOver;
   dropdown.onfocusout = this.mouseOut;
Device
independence
Mobile phones

The Mobile Web is finally coming,
and thanks to Vodafone I'm able to
give you some information,
although the subject remains a tricky
one.
Mobile phones – input modes

On mobile phones there are three
input modes:
- Touch
- Cursor (or rather, pseudo-cursor)
- Four-way navigation (“arrow” keys)
Opera Mini 4.2
on Nokia E71

Pseudo-
cursor input
mode
Opera Mobile
8.00 on
Motorola V3xx

Four-way
navigation
NetFront on
Sony Ericsson
K770i

Four-way
navigation,
but which
link do you
follow when
you click?
Mobile phones – events

In such an environment, what does
“mouseover” mean?

And what about mouseout,
mousemove, mousedown, mouseup?

And click?
Mobile phones – events

I set up a test in which I “click” on a
<div> element and see which events
take place.

First some good news:
S60 WebKit on
Nokia E71
Input: cursor

The same as
desktop
browsers
Opera Mobile
9.5 on HTC
Touch Diamond
Input: touch

This is the
same as the
iPhone does.
Mobile phones – events

So Nokia cursor phones behave
exactly as desktop computers,

while the latest Opera behaves exactly
as the iPhone.
Mobile phones – events

iPhone/Opera model:

As soon as the user touches an element
mouseover, mousemove, mousedown,
mouseup, and click fire,
and the :hover styles are applied.

When user touches another element, mouseout
fires and :hover styles are removed
Mobile phones – events

Now for some bad news.
Blackberry
Storm
Input: touch

No
mouseover,
-out, or
-move
NetFront on
Samsung F700
Input: touch

Where's the
click?
Mobile phones – events

These are only 4 of the 19 browsers I
tested,
and there are hundreds of browsers on
mobile phones.
Mobile phones – events

General rules for events on mobile
phones 1/3:
- use click (and let's politely but firmly give
the finger to browsers that do not support it)
- forget about the mouse events

In fact, I think the time has come to
retire the mouse events on all devices
(with a few exceptions)
Mobile phones – events

General rules for events on mobile
phones 2/3:
- use the resize AND the
orientationchange event

orientationchange is supported only by iPhone
and Blackberry
resize is supported by Opera and all WebKits
NetFront doesn't support either – too bad
Mobile phones – events

General rules for events on mobile
phones 3/3:
- use key events only for setting
general access keys;
and NOT for reading out user input in a form
field

You should read out the field's value instead.
Event compatibility for desktop:

http://quirksmode.org/dom/events

Mobile compatibility
(work in progress)

http://quirksmode.org/m/
Thank you
for your attention
Questions?
Ask away.
Or ask me on Twitter
http://twitter.com/ppk
or on my site
http://quirksmode.org

More Related Content

What's hot

JavaScript APIs - The Web is the Platform - MDN Hack Day, Santiago, Chile
JavaScript APIs - The Web is the Platform - MDN Hack Day, Santiago, ChileJavaScript APIs - The Web is the Platform - MDN Hack Day, Santiago, Chile
JavaScript APIs - The Web is the Platform - MDN Hack Day, Santiago, ChileRobert Nyman
 
JavaScript APIs - The Web is the Platform - MozCamp, Buenos Aires
JavaScript APIs - The Web is the Platform - MozCamp, Buenos AiresJavaScript APIs - The Web is the Platform - MozCamp, Buenos Aires
JavaScript APIs - The Web is the Platform - MozCamp, Buenos AiresRobert Nyman
 
JavaScript APIs - The Web is the Platform - MDN Hack Day, Montevideo
JavaScript APIs - The Web is the Platform - MDN Hack Day, MontevideoJavaScript APIs - The Web is the Platform - MDN Hack Day, Montevideo
JavaScript APIs - The Web is the Platform - MDN Hack Day, MontevideoRobert Nyman
 
Special Events: Beyond Custom Events
Special Events: Beyond Custom EventsSpecial Events: Beyond Custom Events
Special Events: Beyond Custom EventsBrandon Aaron
 
JavaScript APIs - The Web is the Platform - MDN Hack Day - Buenos Aires
JavaScript APIs - The Web is the Platform - MDN Hack Day - Buenos AiresJavaScript APIs - The Web is the Platform - MDN Hack Day - Buenos Aires
JavaScript APIs - The Web is the Platform - MDN Hack Day - Buenos AiresRobert Nyman
 
Getting Touchy Feely with the Web
Getting Touchy Feely with the WebGetting Touchy Feely with the Web
Getting Touchy Feely with the WebAndrew Fisher
 
KODE JS POKENNNNN
KODE JS POKENNNNNKODE JS POKENNNNN
KODE JS POKENNNNNPipo Atem
 
The Wonderful-Amazing-Orientation-Motion-Sensormatic Machine
The Wonderful-Amazing-Orientation-Motion-Sensormatic MachineThe Wonderful-Amazing-Orientation-Motion-Sensormatic Machine
The Wonderful-Amazing-Orientation-Motion-Sensormatic MachineAndrew Fisher
 
How kris-writes-symfony-apps-london
How kris-writes-symfony-apps-londonHow kris-writes-symfony-apps-london
How kris-writes-symfony-apps-londonKris Wallsmith
 
JavaScript APIs - The Web is the Platform - MDN Hack Day, Sao Paulo
JavaScript APIs - The Web is the Platform - MDN Hack Day, Sao PauloJavaScript APIs - The Web is the Platform - MDN Hack Day, Sao Paulo
JavaScript APIs - The Web is the Platform - MDN Hack Day, Sao PauloRobert Nyman
 
DOM Scripting Toolkit - jQuery
DOM Scripting Toolkit - jQueryDOM Scripting Toolkit - jQuery
DOM Scripting Toolkit - jQueryRemy Sharp
 
Leave No One Behind with HTML5 - FFWD.PRO, Croatia
Leave No One Behind with HTML5 - FFWD.PRO, CroatiaLeave No One Behind with HTML5 - FFWD.PRO, Croatia
Leave No One Behind with HTML5 - FFWD.PRO, CroatiaRobert Nyman
 
amsterdamjs - jQuery 1.5
amsterdamjs - jQuery 1.5amsterdamjs - jQuery 1.5
amsterdamjs - jQuery 1.5mennovanslooten
 
JavaScript From Scratch: Events
JavaScript From Scratch: EventsJavaScript From Scratch: Events
JavaScript From Scratch: EventsMichael Girouard
 
HTML5, The Open Web, and what it means for you - MDN Hack Day, Sao Paulo
HTML5, The Open Web, and what it means for you - MDN Hack Day, Sao PauloHTML5, The Open Web, and what it means for you - MDN Hack Day, Sao Paulo
HTML5, The Open Web, and what it means for you - MDN Hack Day, Sao PauloRobert Nyman
 
Getting classy with ES6
Getting classy with ES6Getting classy with ES6
Getting classy with ES6Andy Sharman
 

What's hot (20)

JavaScript APIs - The Web is the Platform - MDN Hack Day, Santiago, Chile
JavaScript APIs - The Web is the Platform - MDN Hack Day, Santiago, ChileJavaScript APIs - The Web is the Platform - MDN Hack Day, Santiago, Chile
JavaScript APIs - The Web is the Platform - MDN Hack Day, Santiago, Chile
 
JavaScript APIs - The Web is the Platform - MozCamp, Buenos Aires
JavaScript APIs - The Web is the Platform - MozCamp, Buenos AiresJavaScript APIs - The Web is the Platform - MozCamp, Buenos Aires
JavaScript APIs - The Web is the Platform - MozCamp, Buenos Aires
 
JavaScript APIs - The Web is the Platform - MDN Hack Day, Montevideo
JavaScript APIs - The Web is the Platform - MDN Hack Day, MontevideoJavaScript APIs - The Web is the Platform - MDN Hack Day, Montevideo
JavaScript APIs - The Web is the Platform - MDN Hack Day, Montevideo
 
Special Events: Beyond Custom Events
Special Events: Beyond Custom EventsSpecial Events: Beyond Custom Events
Special Events: Beyond Custom Events
 
JavaScript APIs - The Web is the Platform - MDN Hack Day - Buenos Aires
JavaScript APIs - The Web is the Platform - MDN Hack Day - Buenos AiresJavaScript APIs - The Web is the Platform - MDN Hack Day - Buenos Aires
JavaScript APIs - The Web is the Platform - MDN Hack Day - Buenos Aires
 
Client Web
Client WebClient Web
Client Web
 
jQuery: Events, Animation, Ajax
jQuery: Events, Animation, AjaxjQuery: Events, Animation, Ajax
jQuery: Events, Animation, Ajax
 
Getting Touchy Feely with the Web
Getting Touchy Feely with the WebGetting Touchy Feely with the Web
Getting Touchy Feely with the Web
 
KODE JS POKENNNNN
KODE JS POKENNNNNKODE JS POKENNNNN
KODE JS POKENNNNN
 
The Wonderful-Amazing-Orientation-Motion-Sensormatic Machine
The Wonderful-Amazing-Orientation-Motion-Sensormatic MachineThe Wonderful-Amazing-Orientation-Motion-Sensormatic Machine
The Wonderful-Amazing-Orientation-Motion-Sensormatic Machine
 
Meet VueJs
Meet VueJsMeet VueJs
Meet VueJs
 
How kris-writes-symfony-apps-london
How kris-writes-symfony-apps-londonHow kris-writes-symfony-apps-london
How kris-writes-symfony-apps-london
 
JavaScript APIs - The Web is the Platform - MDN Hack Day, Sao Paulo
JavaScript APIs - The Web is the Platform - MDN Hack Day, Sao PauloJavaScript APIs - The Web is the Platform - MDN Hack Day, Sao Paulo
JavaScript APIs - The Web is the Platform - MDN Hack Day, Sao Paulo
 
DOM Scripting Toolkit - jQuery
DOM Scripting Toolkit - jQueryDOM Scripting Toolkit - jQuery
DOM Scripting Toolkit - jQuery
 
Leave No One Behind with HTML5 - FFWD.PRO, Croatia
Leave No One Behind with HTML5 - FFWD.PRO, CroatiaLeave No One Behind with HTML5 - FFWD.PRO, Croatia
Leave No One Behind with HTML5 - FFWD.PRO, Croatia
 
amsterdamjs - jQuery 1.5
amsterdamjs - jQuery 1.5amsterdamjs - jQuery 1.5
amsterdamjs - jQuery 1.5
 
Events Lecture Notes
Events Lecture NotesEvents Lecture Notes
Events Lecture Notes
 
JavaScript From Scratch: Events
JavaScript From Scratch: EventsJavaScript From Scratch: Events
JavaScript From Scratch: Events
 
HTML5, The Open Web, and what it means for you - MDN Hack Day, Sao Paulo
HTML5, The Open Web, and what it means for you - MDN Hack Day, Sao PauloHTML5, The Open Web, and what it means for you - MDN Hack Day, Sao Paulo
HTML5, The Open Web, and what it means for you - MDN Hack Day, Sao Paulo
 
Getting classy with ES6
Getting classy with ES6Getting classy with ES6
Getting classy with ES6
 

Viewers also liked

Understanding JavaScript Event-based Interactions
Understanding JavaScript Event-based InteractionsUnderstanding JavaScript Event-based Interactions
Understanding JavaScript Event-based InteractionsSALT Lab @ UBC
 
Dive into javascript event
Dive into javascript eventDive into javascript event
Dive into javascript eventGoddy Zhao
 
JavaScript event handling assignment
JavaScript  event handling assignment JavaScript  event handling assignment
JavaScript event handling assignment Soham Sengupta
 
JavaScript - An Introduction
JavaScript - An IntroductionJavaScript - An Introduction
JavaScript - An IntroductionManvendra Singh
 

Viewers also liked (7)

Understanding JavaScript Event-based Interactions
Understanding JavaScript Event-based InteractionsUnderstanding JavaScript Event-based Interactions
Understanding JavaScript Event-based Interactions
 
Dive into javascript event
Dive into javascript eventDive into javascript event
Dive into javascript event
 
JavaScript event handling assignment
JavaScript  event handling assignment JavaScript  event handling assignment
JavaScript event handling assignment
 
JavaScript and BOM events
JavaScript and BOM eventsJavaScript and BOM events
JavaScript and BOM events
 
Javascript and DOM
Javascript and DOMJavascript and DOM
Javascript and DOM
 
JavaScript - An Introduction
JavaScript - An IntroductionJavaScript - An Introduction
JavaScript - An Introduction
 
jQuery Essentials
jQuery EssentialsjQuery Essentials
jQuery Essentials
 

Similar to Yahoo presentation: JavaScript Events

Voices That Matter: JavaScript Events
Voices That Matter: JavaScript EventsVoices That Matter: JavaScript Events
Voices That Matter: JavaScript EventsPeter-Paul Koch
 
Getting touchy - an introduction to touch and pointer events / TPAC 2016 / Li...
Getting touchy - an introduction to touch and pointer events / TPAC 2016 / Li...Getting touchy - an introduction to touch and pointer events / TPAC 2016 / Li...
Getting touchy - an introduction to touch and pointer events / TPAC 2016 / Li...Patrick Lauke
 
Getting touchy - an introduction to touch events / Web Standards Days / Mosco...
Getting touchy - an introduction to touch events / Web Standards Days / Mosco...Getting touchy - an introduction to touch events / Web Standards Days / Mosco...
Getting touchy - an introduction to touch events / Web Standards Days / Mosco...Patrick Lauke
 
There is something about Event
There is something about EventThere is something about Event
There is something about EventEddie Kao
 
Signalsで Event処理を簡単に
Signalsで Event処理を簡単にSignalsで Event処理を簡単に
Signalsで Event処理を簡単にHiroaki Okubo
 
JavaScript - Chapter 11 - Events
 JavaScript - Chapter 11 - Events  JavaScript - Chapter 11 - Events
JavaScript - Chapter 11 - Events WebStackAcademy
 
Getting touchy - an introduction to touch events / Webinale / Berlin 04.06.2013
Getting touchy - an introduction to touch events / Webinale / Berlin 04.06.2013Getting touchy - an introduction to touch events / Webinale / Berlin 04.06.2013
Getting touchy - an introduction to touch events / Webinale / Berlin 04.06.2013Patrick Lauke
 
Mobile HTML, CSS, and JavaScript
Mobile HTML, CSS, and JavaScriptMobile HTML, CSS, and JavaScript
Mobile HTML, CSS, and JavaScriptfranksvalli
 
jQuery 1.7 Events
jQuery 1.7 EventsjQuery 1.7 Events
jQuery 1.7 Eventsdmethvin
 
Java Event Handling
Java Event HandlingJava Event Handling
Java Event HandlingShraddha
 
Getting touchy - an introduction to touch events / Sud Web / Avignon 17.05.2013
Getting touchy - an introduction to touch events / Sud Web / Avignon 17.05.2013Getting touchy - an introduction to touch events / Sud Web / Avignon 17.05.2013
Getting touchy - an introduction to touch events / Sud Web / Avignon 17.05.2013Patrick Lauke
 
Event Handling in java
Event Handling in javaEvent Handling in java
Event Handling in javaGoogle
 
Flash Lite & Touch: build an iPhone-like dynamic list
Flash Lite & Touch: build an iPhone-like dynamic listFlash Lite & Touch: build an iPhone-like dynamic list
Flash Lite & Touch: build an iPhone-like dynamic listSmall Screen Design
 
Getting touchy - an introduction to touch events / Sainté Mobile Days / Saint...
Getting touchy - an introduction to touch events / Sainté Mobile Days / Saint...Getting touchy - an introduction to touch events / Sainté Mobile Days / Saint...
Getting touchy - an introduction to touch events / Sainté Mobile Days / Saint...Patrick Lauke
 
Event handling
Event handlingEvent handling
Event handlingswapnac12
 
Composite Applications with WPF and PRISM
Composite Applications with WPF and PRISMComposite Applications with WPF and PRISM
Composite Applications with WPF and PRISMEyal Vardi
 

Similar to Yahoo presentation: JavaScript Events (20)

Voices That Matter: JavaScript Events
Voices That Matter: JavaScript EventsVoices That Matter: JavaScript Events
Voices That Matter: JavaScript Events
 
Getting touchy - an introduction to touch and pointer events / TPAC 2016 / Li...
Getting touchy - an introduction to touch and pointer events / TPAC 2016 / Li...Getting touchy - an introduction to touch and pointer events / TPAC 2016 / Li...
Getting touchy - an introduction to touch and pointer events / TPAC 2016 / Li...
 
Getting touchy - an introduction to touch events / Web Standards Days / Mosco...
Getting touchy - an introduction to touch events / Web Standards Days / Mosco...Getting touchy - an introduction to touch events / Web Standards Days / Mosco...
Getting touchy - an introduction to touch events / Web Standards Days / Mosco...
 
There is something about Event
There is something about EventThere is something about Event
There is something about Event
 
The touch events
The touch eventsThe touch events
The touch events
 
Touchevents
ToucheventsTouchevents
Touchevents
 
Signalsで Event処理を簡単に
Signalsで Event処理を簡単にSignalsで Event処理を簡単に
Signalsで Event処理を簡単に
 
2011 07-hiyoko
2011 07-hiyoko2011 07-hiyoko
2011 07-hiyoko
 
Events.pdf
Events.pdfEvents.pdf
Events.pdf
 
JavaScript - Chapter 11 - Events
 JavaScript - Chapter 11 - Events  JavaScript - Chapter 11 - Events
JavaScript - Chapter 11 - Events
 
Getting touchy - an introduction to touch events / Webinale / Berlin 04.06.2013
Getting touchy - an introduction to touch events / Webinale / Berlin 04.06.2013Getting touchy - an introduction to touch events / Webinale / Berlin 04.06.2013
Getting touchy - an introduction to touch events / Webinale / Berlin 04.06.2013
 
Mobile HTML, CSS, and JavaScript
Mobile HTML, CSS, and JavaScriptMobile HTML, CSS, and JavaScript
Mobile HTML, CSS, and JavaScript
 
jQuery 1.7 Events
jQuery 1.7 EventsjQuery 1.7 Events
jQuery 1.7 Events
 
Java Event Handling
Java Event HandlingJava Event Handling
Java Event Handling
 
Getting touchy - an introduction to touch events / Sud Web / Avignon 17.05.2013
Getting touchy - an introduction to touch events / Sud Web / Avignon 17.05.2013Getting touchy - an introduction to touch events / Sud Web / Avignon 17.05.2013
Getting touchy - an introduction to touch events / Sud Web / Avignon 17.05.2013
 
Event Handling in java
Event Handling in javaEvent Handling in java
Event Handling in java
 
Flash Lite & Touch: build an iPhone-like dynamic list
Flash Lite & Touch: build an iPhone-like dynamic listFlash Lite & Touch: build an iPhone-like dynamic list
Flash Lite & Touch: build an iPhone-like dynamic list
 
Getting touchy - an introduction to touch events / Sainté Mobile Days / Saint...
Getting touchy - an introduction to touch events / Sainté Mobile Days / Saint...Getting touchy - an introduction to touch events / Sainté Mobile Days / Saint...
Getting touchy - an introduction to touch events / Sainté Mobile Days / Saint...
 
Event handling
Event handlingEvent handling
Event handling
 
Composite Applications with WPF and PRISM
Composite Applications with WPF and PRISMComposite Applications with WPF and PRISM
Composite Applications with WPF and PRISM
 

More from Peter-Paul Koch

Rethinking the mobile web
Rethinking the mobile webRethinking the mobile web
Rethinking the mobile webPeter-Paul Koch
 
The mobile browser world
The mobile browser worldThe mobile browser world
The mobile browser worldPeter-Paul Koch
 
The future of the mobile web
The future of the mobile webThe future of the mobile web
The future of the mobile webPeter-Paul Koch
 
The mobile browser world
The mobile browser worldThe mobile browser world
The mobile browser worldPeter-Paul Koch
 
The touch events - WebExpo
The touch events - WebExpoThe touch events - WebExpo
The touch events - WebExpoPeter-Paul Koch
 
The Mobile Web - Fronteers 2009
The Mobile Web - Fronteers 2009The Mobile Web - Fronteers 2009
The Mobile Web - Fronteers 2009Peter-Paul Koch
 
State of the Mobile Browsers
State of the Mobile BrowsersState of the Mobile Browsers
State of the Mobile BrowsersPeter-Paul Koch
 
The Ajax Experience: State Of The Browsers
The Ajax Experience: State Of The BrowsersThe Ajax Experience: State Of The Browsers
The Ajax Experience: State Of The BrowsersPeter-Paul Koch
 
An Event Apart Boston: Principles of Unobtrusive JavaScript
An Event Apart Boston: Principles of Unobtrusive JavaScriptAn Event Apart Boston: Principles of Unobtrusive JavaScript
An Event Apart Boston: Principles of Unobtrusive JavaScriptPeter-Paul Koch
 
Google presentation: The Open Web goes mobile
Google presentation: The Open Web goes mobileGoogle presentation: The Open Web goes mobile
Google presentation: The Open Web goes mobilePeter-Paul Koch
 

More from Peter-Paul Koch (14)

Rethinking the mobile web
Rethinking the mobile webRethinking the mobile web
Rethinking the mobile web
 
The mobile browser world
The mobile browser worldThe mobile browser world
The mobile browser world
 
The future of the mobile web
The future of the mobile webThe future of the mobile web
The future of the mobile web
 
The mobile browser world
The mobile browser worldThe mobile browser world
The mobile browser world
 
The touch events
The touch eventsThe touch events
The touch events
 
JSON over SMS
JSON over SMSJSON over SMS
JSON over SMS
 
The touch events - WebExpo
The touch events - WebExpoThe touch events - WebExpo
The touch events - WebExpo
 
Samsung
SamsungSamsung
Samsung
 
The Mobile Web - Fronteers 2009
The Mobile Web - Fronteers 2009The Mobile Web - Fronteers 2009
The Mobile Web - Fronteers 2009
 
State of the Mobile Browsers
State of the Mobile BrowsersState of the Mobile Browsers
State of the Mobile Browsers
 
Vodafone Widget Camp
Vodafone Widget CampVodafone Widget Camp
Vodafone Widget Camp
 
The Ajax Experience: State Of The Browsers
The Ajax Experience: State Of The BrowsersThe Ajax Experience: State Of The Browsers
The Ajax Experience: State Of The Browsers
 
An Event Apart Boston: Principles of Unobtrusive JavaScript
An Event Apart Boston: Principles of Unobtrusive JavaScriptAn Event Apart Boston: Principles of Unobtrusive JavaScript
An Event Apart Boston: Principles of Unobtrusive JavaScript
 
Google presentation: The Open Web goes mobile
Google presentation: The Open Web goes mobileGoogle presentation: The Open Web goes mobile
Google presentation: The Open Web goes mobile
 

Recently uploaded

"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 

Recently uploaded (20)

"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 

Yahoo presentation: JavaScript Events

  • 1. Hell is other browsers - Sartre JavaScript Events Peter-Paul Koch (ppk) http://quirksmode.org http://twitter.com/ppk Yahoo!, 23 April 2009
  • 2.
  • 4. Today's program: - the key events - the change event - delegating the focus event - first results of mobile event tests
  • 6. keydown When a key is depressed. Repeats. keypress keyup
  • 7. keydown When a key is depressed. Repeats. keypress When a character key is depressed. Repeats. keyup
  • 8. keydown When a key is depressed. Repeats. keypress When a character key is depressed. Repeats. keyup When a key is released.
  • 11. Originally this theory was created by Microsoft. Safari has copied it. It's the only theory; Firefox and Opera just fire some random events.
  • 12. keydown When a key is depressed. Repeats. keypress When a character key is depressed. Repeats.
  • 13. Which key did my user press? Two properties: keyCode and charCode Two bits of data: - the key code - the character code
  • 14. Which key did my user press? Obviously, having one property contain one bit of data and the other property the other would be far too simple.
  • 15. Which key did my user press? keyCode - onkeydown: key code - onkeypress: character code
  • 16. Which key did my user press? charCode - onkeydown: 0 - onkeypress: character code
  • 17. Which key did my user press? If you need the key: el.onkeydown = function (e) { e = e || window.event; var realKey = e.keyCode; }
  • 18. Which key did my user press? If you need the key: el.onkeydown = function (e) { e = e || window.event; var realKey = e.keyCode; }
  • 19. Which key did my user press? If you need the character: el.onkeypress = function (e) { e = e || window.event; var char = e.keyCode || e.charCode; }
  • 20. Which key did my user press? If you need the character: el.onkeypress = function (e) { e = e || window.event; var char = e.keyCode || e.charCode; }
  • 21. How can I prevent the default action? el.onkeydown = function (e) { e = e || window.event; var key = e.keyCode; if (key is incorrect) { // cancel default action } }
  • 22. How can I prevent the default action? el.onkeydown = function (e) { e = e || window.event; var key = e.keyCode; if (key is incorrect) { // cancel default action } }
  • 24. The change event fires when the value of a form field is changed. This could be a very useful event; after all it fires only when the user actually changes something instead of whenever he focuses on a form field
  • 25. - text fields - select boxes - checkboxes and radios
  • 26. - text fields - select boxes - checkboxes and radios focus blur No change event. The value hasn't been modified.
  • 27. - text fields - select boxes - checkboxes and radios focus blur Change event. The value has been modified.
  • 28. - text fields - select boxes - checkboxes and radios Mouse: Click on select
  • 29. - text fields - select boxes - checkboxes and radios Mouse: Click on new option CHANGE
  • 30. - text fields - select boxes - checkboxes and radios Keyboard: focus Focus on select
  • 31. - text fields - select boxes - checkboxes and radios Keyboard: focus arrow Arrow keys to move to other option CHANGE
  • 32. - text fields - select boxes - checkboxes and radios This is a BUG! Arrow keys to move to other option CHANGE
  • 33. - text fields - select boxes - checkboxes and radios Keyboard: focus arrow Arrow keys to move to other option
  • 34. - text fields - select boxes - checkboxes and radios Keyboard: focus arrow blur Blur select box. CHANGE
  • 35. - text fields - select boxes - checkboxes and radios click CHANGE when the checked property changes.
  • 36. - text fields - select boxes - checkboxes and radios click ...
  • 37. - text fields - select boxes - checkboxes and radios click blur CHANGE when the element loses the focus.
  • 38. - text fields - select boxes - checkboxes and radios This is a BUG! CHANGE when the element loses the focus.
  • 40. Event delegation <ul> <li><a href=”#”>Multimedialize</a> <ul> <li><a href=”#”>Sound</a></li> <li><a href=”#”>Java applets</a></li> </ul></li> <li><a href=”#”>Ajaxify</a> <ul> <li><a href=”#”>Web 2.0</a></li> <li><a href=”#”>Web 3.0</a></li> <li><a href=”#”>Web 4.0b</a></li> </ul></li> </ul>
  • 42. Event delegation The event bubbles up to the <ul> var dropdown = { anyway. (dropdown) { init: function dropdown.onmouseover = mouseOver; dropdown.onmouseout = mouseOut; So why not handle it at that level? } } Saves a lot of event handlers.
  • 43. Event delegation var dropdown = { init: function (dropdown) { dropdown.onmouseover = mouseOver; dropdown.onmouseout = mouseOut; } } Works in all browsers.
  • 44.  Event delegation But suppose someone doesn't use a mouse at all, but the keyboard how does the menu fold out?
  • 46.  Event delegation var dropdown = { init: function (dropdown) { dropdown.onmouseover = this.mouseOver; dropdown.onmouseout = this.mouseOut; } }
  • 47. Event delegation var dropdown = { init: function (dropdown) { dropdown.onmouseover = this.mouseOver; dropdown.onmouseout = this.mouseOut; } } Doesn't work without a mouse.
  • 48. Event delegation var dropdown = { init: function (dropdown) { dropdown.onmouseover = this.mouseOver; dropdown.onmouseout = this.mouseOut; } } We need events that tell us whether the user enters or leaves a link. focus and blur
  • 49. Event delegation var dropdown = { init: function (dropdown) { dropdown.onmouseover = dropdown.onfocus = this.mouseOver; dropdown.onmouseout = dropdown.onblur = this.mouseOut; } }
  • 50. Event delegation var dropdown = { init: function (dropdown) { dropdown.onmouseover = dropdown.onfocus = this.mouseOver; dropdown.onmouseout = dropdown.onblur = this.mouseOut; } } Doesn't work.
  • 51. Event delegation var dropdown = { init: function (dropdown) { dropdown.onmouseover = dropdown.onfocus = this.mouseOver; dropdown.onmouseout = dropdown.onblur = this.mouseOut; } } Focus and blur don't bubble.
  • 52. To bubble or not to bubble Two kinds of events: 1) Mouse and key events 2) Interface events
  • 53. To bubble or not to bubble Two kinds of events: 1) Mouse and key events 2) Interface events Fire when the user initiates a device- specific action. mouseover, mouseout, click, keydown, keypress
  • 54. To bubble or not to bubble Two kinds of events: 1) Mouse and key events 2) Interface events In general they bubble.
  • 55. To bubble or not to bubble Two kinds of events: 1) Mouse and key events 2) Interface events Fire when a certain event takes place, regardless of how it was initialised. load, change, submit, focus, blur
  • 56. To bubble or not to bubble Two kinds of events: 1) Mouse and key events 2) Interface events In general they don't bubble.
  • 57. Event delegation var dropdown = { init: function (dropdown) { dropdown.onmouseover = this.mouseOver; dropdown.onmouseout = this.mouseOut; var x = dropdown.getElementsByTagName('a'); for (var i=0;i<x.length;i++) { x[i].onfocus = this.mouseOver; x[i].onblur = this.mouseOut; } } }
  • 58. Event delegation So we're stuck with setting a focus and blur event on every single link. Or are we ... ?
  • 59. Event delegation Event capturing to the rescue. Event capturing is the opposite of event bubbling, and it is supported in all W3C- compliant browsers.
  • 62. Event delegation The point is that if you capture a focus event, event handlers on the target element's ancestors are executed.
  • 63. Event bubbling Focus on a: a.onfocus executed
  • 64. Event capturing Focus on a: ul.onfocus, li.onfocus and a.onfocus executed
  • 65.  Event capturing and bubbling Why this difference? I have no idea. Maybe it's time to have bubbling and capturing act the same. The current situation doesn't make sense (though it's useful).
  • 66.  Event delegation var dropdown = { init: function (dropdown) { dropdown.onmouseover = this.mouseOver; dropdown.onmouseout = this.mouseOut; } }
  • 67.  Event delegation var dropdown = { init: function (dropdown) { dropdown.onmouseover = this.mouseOver; dropdown.onmouseout = this.mouseOut; dropdown.addEventListener ('focus',this.mouseOver,true); dropdown.addEventListener ('blur',this.mouseOut,true); } }
  • 68.  Event delegation var dropdown = { init: function (dropdown) { dropdown.onmouseover = this.mouseOver; dropdown.onmouseout = this.mouseOut; if (dropdown.addEventListener) { dropdown.addEventListener ('focus',this.mouseOver,true); dropdown.addEventListener ('blur',this.mouseOut,true); } } }
  • 69.  Event delegation And what about IE? It doesn't support addEventListener, but fortunately it supports the focusin and focusout events which are like focus and blur, except that they bubble.
  • 70.  Event delegation var dropdown = { init: function (dropdown) { dropdown.onmouseover = this.mouseOver; dropdown.onmouseout = this.mouseOut; if (dropdown.addEventListener) { dropdown.addEventListener ('focus',this.mouseOver,true); dropdown.addEventListener ('blur',this.mouseOut,true); } } }
  • 71.  Event delegation var dropdown = { init: function (dropdown) { dropdown.onmouseover = this.mouseOver; dropdown.onmouseout = this.mouseOut; if (dropdown.addEventListener) { dropdown.addEventListener ('focus',this.mouseOver,true); dropdown.addEventListener ('blur',this.mouseOut,true); } dropdown.onfocusin = this.mouseOver; dropdown.onfocusout = this.mouseOut }
  • 72.  Event delegation dropdown.onmouseover = this.mouseOver; dropdown.onmouseout = this.mouseOut; if (dropdown.addEventListener) { dropdown.addEventListener ('focus',this.mouseOver,true); dropdown.addEventListener ('blur',this.mouseOut,true); } dropdown.onfocusin = this.mouseOver; dropdown.onfocusout = this.mouseOut;
  • 74.
  • 75. Mobile phones The Mobile Web is finally coming, and thanks to Vodafone I'm able to give you some information, although the subject remains a tricky one.
  • 76. Mobile phones – input modes On mobile phones there are three input modes: - Touch - Cursor (or rather, pseudo-cursor) - Four-way navigation (“arrow” keys)
  • 77. Opera Mini 4.2 on Nokia E71 Pseudo- cursor input mode
  • 78. Opera Mobile 8.00 on Motorola V3xx Four-way navigation
  • 79. NetFront on Sony Ericsson K770i Four-way navigation, but which link do you follow when you click?
  • 80. Mobile phones – events In such an environment, what does “mouseover” mean? And what about mouseout, mousemove, mousedown, mouseup? And click?
  • 81. Mobile phones – events I set up a test in which I “click” on a <div> element and see which events take place. First some good news:
  • 82. S60 WebKit on Nokia E71 Input: cursor The same as desktop browsers
  • 83. Opera Mobile 9.5 on HTC Touch Diamond Input: touch This is the same as the iPhone does.
  • 84. Mobile phones – events So Nokia cursor phones behave exactly as desktop computers, while the latest Opera behaves exactly as the iPhone.
  • 85. Mobile phones – events iPhone/Opera model: As soon as the user touches an element mouseover, mousemove, mousedown, mouseup, and click fire, and the :hover styles are applied. When user touches another element, mouseout fires and :hover styles are removed
  • 86. Mobile phones – events Now for some bad news.
  • 88. NetFront on Samsung F700 Input: touch Where's the click?
  • 89. Mobile phones – events These are only 4 of the 19 browsers I tested, and there are hundreds of browsers on mobile phones.
  • 90. Mobile phones – events General rules for events on mobile phones 1/3: - use click (and let's politely but firmly give the finger to browsers that do not support it) - forget about the mouse events In fact, I think the time has come to retire the mouse events on all devices (with a few exceptions)
  • 91. Mobile phones – events General rules for events on mobile phones 2/3: - use the resize AND the orientationchange event orientationchange is supported only by iPhone and Blackberry resize is supported by Opera and all WebKits NetFront doesn't support either – too bad
  • 92. Mobile phones – events General rules for events on mobile phones 3/3: - use key events only for setting general access keys; and NOT for reading out user input in a form field You should read out the field's value instead.
  • 93. Event compatibility for desktop: http://quirksmode.org/dom/events Mobile compatibility (work in progress) http://quirksmode.org/m/
  • 94. Thank you for your attention
  • 95. Questions? Ask away. Or ask me on Twitter http://twitter.com/ppk or on my site http://quirksmode.org