10

How to put <br /> only in div contenteditable while user is pressing ENTER key? I must manage the content of that div in XML after send, but some browsers translate new lines as <p>, some (in example Google Chrome) as <div>.

The good solution will be force to make new lines the same in all browsers (only <p> or only <div>) too.

PS: I'm using jQuery and PHP.

Zozo
  • 870
  • 1
  • 8
  • 27
  • 1
    Take a look at this question: http://stackoverflow.com/questions/2220939/force-ie-contenteditable-element-to-create-line-breaks-on-enter-key-without-brea – Nick Craver Jul 20 '10 at 10:08
  • For firefox take a look at https://developer.mozilla.org/en/rich-text_editing_in_mozilla. Look for the argument "insertBrOnReturn". Not sure for IE though – Mechlar Aug 11 '10 at 19:05

3 Answers3

1

How about trapping the user keyboard event of pressing the Enter key?

kheya
  • 7,546
  • 20
  • 77
  • 109
0

Not sure, but note that <shift><enter> generally inserts a <br />, I belive.

I wonder if you could force a shift in onKeypress?

bnieland
  • 6,047
  • 4
  • 40
  • 66
  • I'm not sure it is possible at all. I've tried to rewrite event keyCode, but it is not possible. – Zozo Aug 19 '10 at 08:32
0

Try this: <div contenteditable="true">test1<div></div></div>

You can force single-spacing when you hit return in a content-editable element by seeding it with an inner DIV like so: