1

How can I make the browser insert <p> tags instead of <br> tags when I press enter in a designMode IFrame? I get inconsistent behavior across Firefox, Chrome and IE and was wondering if there was some way to normalize this.

  • You say designMode iFrame- did you mean textarea? Also, are you using any Javascript libraries (like jQuery)? – element119 Aug 28 '11 at 23:18
  • I mean IFrame with `designMode = 'on'`, so the WYSIWYG textarea type thing, and yes, I'm using jQuery. –  Aug 29 '11 at 00:24

1 Answers1

1

It seems you can't. Behaviour is not standardized and control for this is rudimentary at best

This is an interesting thread from May thie year on the matter: http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2011-May/031577.html . It's discussing contenteditable rather than designMode but they're effectively very similar.

An email on the thread ( http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2011-May/031604.html ) from Simon Pieters (zcorpan) of Opera says:

Opera 11.10 has introduced document.execCommand('opera-defaultblock','','div') to switch to using <div>s instead of <p>s. ('p' is also allowed to switch back.) Apparently WebKit considers implementing this as well. https://bugs.webkit.org/show_bug.cgi?id=59961

Further in the thread there's also this email http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2011-May/031685.html by Markus Ernst including this comment:

I assume there are use cases for both generating <p>s and <br>s. The IE/Opera approach has the advantage of allowing both, which is perfect for text and basic HTML editing. From a WYSIWYG POV it might be best to offer both options, so authors are not encouraged to add server-side processing to change the output, which would break WYSIWYG.

If the behavior is settable, it might even be a good idea to leave the choice of the standard behavior to the UAs. Authors who have a reason to care can set their preferred behavior, while other authors might prefer to leave it as it was, so there is no change for their existing users.

There's lots more on the thread about what people at the various browser makers think ought to happen, comments on some very strange existing behaviours, and general discussion about the problem involved in implementing it at all.

The currently very alpha spec for all this is at http://aryeh.name/spec/editing/editing.html

Alohci
  • 78,296
  • 16
  • 112
  • 156
  • I've looked at CKEditor and TinyMCE and they both seem to be able to force the browser to insert `

    ` tags over `
    ` tags -- any idea how that's implemented? (and no, I can't really just use one of those editors)

    –  Aug 29 '11 at 00:53
  • The thread does mention this. I think it says they capture and override the enter key and apply their own set of actions instead. But it didn't go into detail as far as I could see. – Alohci Aug 29 '11 at 00:58