Opened 12 years ago

Closed 12 years ago

#1274 closed defect (fixed)

onKeyPress not fired for special keys (e.g., backspace) in Safari 3.1

Reported by: nicholasbs Owned by: gogo
Priority: normal Milestone: 0.96
Component: Xinha Core Version: trunk
Severity: normal Keywords:


At present, if a plugin wants to respond to key events for special keys by implementing an onKeyPress method, it cannot do so in a way that is compatible with Safari 3.1.

This is due to a known change in Safari, which as of version 3.1 does not fire keypress events for special keys (i.e., it fires them for characters, such as 'a' or 'b', but it does not for backspace and other non-character keys). See this message on the WebKit? mailing list for details.

Xinha uses a function isKeyEvent to determine if a given event is a key event, which in WebKit?.js looks like this:

/** Determine if the given event object is a keydown/press event.
 *  @param event Event 
 *  @returns true|false
Xinha.prototype.isKeyEvent = function(event)
  return event.type == "keypress";

From the above it's clear that isKeyEvent will return false for keydown events. I propose either changing 'keypress' in the code above to 'keydown' (which fires in Safari for both character and non-character keys) or adding a separate event, so that Xinha plugins can choose between implementing onKeyDown or onKeyPress.

What do others think?

Change History (3)

comment:1 Changed 12 years ago by ray

Wouldn't "keyup" be more appropriate, considering the time when onKeyPress is fired is when the key is released again?

comment:2 Changed 12 years ago by ray

Only just having read the linked mailing list entry, I see they say the want to "match Internet Explorer much more closely". Looking at the IE implementation of Xinha.prototype.isKeyEvent, I understand it uses "keydown", too, so this seems to be just fine.

comment:3 Changed 12 years ago by nicholasbs

  • Resolution set to fixed
  • Status changed from new to closed

Changset r1039 includes this fix.

Note: See TracTickets for help on using tickets.