Rolando
Rolando

Reputation: 62644

Javascript iPad Return Key event?

On a JavaScript page, I pop up an alert if the user hits the enter key by using

if(evt.keyCode == 13){
    alert("Return Key Pressed");
}

but the event does not fire when I hit the return key on the iPad. How do I catch the event?

Upvotes: 3

Views: 12397

Answers (2)

johnl
johnl

Reputation: 234

According to https://api.jquery.com/keypress/

The keypress event is sent to an element when the browser registers keyboard input. This is similar to the keydown event, except that modifier and non-printing keys such as Shift, Esc, and delete trigger keydown events but not keypress events. Other differences between the two events may arise depending on platform and browser.

A keypress event handler can be attached to any element, but the event is only sent to the element that has the focus. Focusable elements can vary between browsers, but form controls can always get focus so are reasonable candidates for this event type.

I moved my return-key listener to an anchor tag, which on IPad is treated as a 'focusable element' similar to form controls.

Upvotes: 0

Nevir
Nevir

Reputation: 8101

The iPad keyboard does fire the keypress event with a key code of 13 if you press return. This sounds like you've got something else going awry

Here's a quick jsfiddle to verify with: http://jsfiddle.net/359wG/

Upvotes: 3

Related Questions