views:

116

answers:

4

Hello, I have got a div with contenteditable that should trigger a < br /> insert on "enter". Everything works fine in IE but Firefox drives me crazy.

this.e.keydown(function(event) {
  if(event.keyCode == 13) {
    var execute = editor.insertHTML(\'<br />\')';
    eval(execute);
    return false;
  } 
});

Firefox ignores < br /> at the end of the div and I guess at the beginning too. Means, if I press "enter" at the middle of a sentence, it works as it should. Trying the same at the end of a sentence (the very last one) it fails.

Any ideas? The same problem we have at the stackoverflow editor preview :-)

Press "enter" at the end > fail ... press "enter" a single letter earlier > newline

A: 

Add this function instead

this.e.keydown(function(event) { if(event.keyCode == 13 || event.charCode == 13) { var execute = editor.insertHTML(\'
\')'; eval(execute); return false; } });

FF reads charCode instead of keyCode.

Deepak Ranjan Jena
A: 

nope, this aint working - the problem has nothing to do with the keycode...

Thom
Please use the *add comment* feature
Álvaro G. Vicario
A: 

You can try inserting <br /><span></span>. This moves the cursor to the next line but doesn't properly resize the container so it isn't perfect.

drewrichards
A: 

@drewrichards

It is working pretty well with < div > instead

Thom