ابحث في الدعم

Avoid support scams. We will never ask you to call or text a phone number or share personal information. Please report suspicious activity using the “Report Abuse” option.

Learn More

FF differs from other browsers - keystroke is swallowed when creating input element

  • 2 (ردّان اثنان)
  • 1 has this problem
  • 3 views
  • آخر ردّ كتبه frankmillman

more options

Hi all

I have found a workaround for this problem, so its importance is low, but I will be interested in any comments.

I am creating a control in javascript which represents an editable grid - a bit like a spreadsheet. The cells consist of 'span' elements with text nodes. I can move around the grid with the keyboard or the mouse.

The user can signal their intent to edit a cell in three ways - double-click, press F2, or just start typing. When any of these are detected, I hide the span element and replace it with a text input element.

If they doubleclick or press F2, the initial content of the input element must be the same as the content of the text node. If they type a character, the initial content must be the character they typed.

In all other browsers I have tested (IE8, Opera, Chrome and Safari) the keystroke entered is still 'active', so it automatically becomes the first character in the input element. In FF, it does not.

My workaround is to store the keystroke entered in a variable, then create the input element, then update the 'value' attribute of the element with the string value of the keystroke, then call setSelectionRange(1, 1) so that the insertion point is positioned after the character.

I can live with this, but it would be nice if I could get FF to behave the same as the others, and render the workaround unnecessary.

Hi all I have found a workaround for this problem, so its importance is low, but I will be interested in any comments. I am creating a control in javascript which represents an editable grid - a bit like a spreadsheet. The cells consist of 'span' elements with text nodes. I can move around the grid with the keyboard or the mouse. The user can signal their intent to edit a cell in three ways - double-click, press F2, or just start typing. When any of these are detected, I hide the span element and replace it with a text input element. If they doubleclick or press F2, the initial content of the input element must be the same as the content of the text node. If they type a character, the initial content must be the character they typed. In all other browsers I have tested (IE8, Opera, Chrome and Safari) the keystroke entered is still 'active', so it automatically becomes the first character in the input element. In FF, it does not. My workaround is to store the keystroke entered in a variable, then create the input element, then update the 'value' attribute of the element with the string value of the keystroke, then call setSelectionRange(1, 1) so that the insertion point is positioned after the character. I can live with this, but it would be nice if I could get FF to behave the same as the others, and render the workaround unnecessary.

All Replies (2)

more options

A good place to ask advice about web development is at the mozillaZine Web Development/Standards Evangelism forum.
The helpers at that forum are more knowledgeable about web development issues.
You need to register at the mozillaZine forum site in order to post at that forum.

See http://forums.mozillazine.org/viewforum.php?f=25

more options

Thanks - I will try there.