1

I create the simplest WYSIWYG editor, but in each browser generated other html code. I use: a.execCommand('useCSS', false, true); a.execCommand('styleWithCSS', false, false); For example: Chrome generate unnecessary div when i use enter key... IE generate <p> tags when go to new line... Firefox generate for me the best code, inserts old br:)

I must create styles for results, by it's too much differences.

Pointy
  • 405,095
  • 59
  • 585
  • 614
kicaj
  • 2,881
  • 5
  • 42
  • 68
  • *Which* editor are you using? *What code* do you use to obtain and manipulate the contents? – Marcel Korpel May 23 '11 at 20:31
  • 1
    Browser differences with `contenteditable` is way too much trouble to try to hack about yourself. I would suggest to use TinyMCE or a comparable ready-made solution. http://tinymce.moxiecode.com/ – DarthJDG May 23 '11 at 20:51

1 Answers1

2

The insertion of div's, p's, or br's when pressing enter/return is NOT controlled with the useCSS/styleWithCSS option. This option is only for styles. What happens when you press enter/return is entirely browser-specific. To normalize the behavior, you can code a key-handler for the return key (code 13) where you insert a <br> or \n or whatever you like when enter is pressed.

See the following questions to get started with writing a key handler for exactly this:

Make a <br> instead of <div></div> by pressing Enter on a contenteditable

Cross browser event handler must capture [ENTER]

Community
  • 1
  • 1
ampersand
  • 4,264
  • 2
  • 24
  • 32