views:

329

answers:

4

Could you please explain how the text in the textarea gets styled in rich-text editors? I've tried to style text in the form but it doesn't change.

Is it JS that recognizes characters typed by the user? How's that done?


Edit:

After a bit of research (Google rules!), I've found some excellent information. For others who might be interested, these links were very helpful to me:

A: 

Usually, the rich text editor will provide a variable to specify a style sheet in. That style sheet will then be loaded and applied to the textarea (Most, if not all, rich text editors use a IFRAME to display the editor in, and obviously styles specified in the main document won't apply to it.)

Pekka
As understand JS replaces the textarea with a IFRAME... Is an iframe sort of the textarea?
David Gore
In IFRAME is a window to a separate document. The textarea is essentially meaningless, it is used only as a data container so that the edited content can be saved through a form. What WYSIYWYG editor are you using?
Pekka
I don't use any... So, is it JS that recognizes characters typed by the user? How's it done?
David Gore
+2  A: 

I think the answer is that what you're looking at is typically NOT an actual <textarea>. It's a <div> or <span> made to look like a text area. A regular HTML textarea doesn't have individual formatting of the text.

"Rich-Text editors" will have controls that modify the contents of the span/div with regular html markup (<strong>, <em>, etc.) to emulate a full-blown rich text editor

Jay Stevens
It's difficult to find out what TinyMCE does, but it uses a textarea in this example: http://tinymce.moxiecode.com/examples/full.php
Otto Allmendinger
Another common technique is to layer an iframe over top of the textarea.
Joel Coehoorn
What is iframe, please?
David Gore
A: 

It's a textarea when you send the HTML to the user but the editor replaced it with a div when it can start.

This way, the code gracefully degrades: Users with unsupported web browsers or disabled JavaScript can still edit the text in the textarea while all the other users get a nice rich text editor.

Aaron Digulla
A: 

Basically, the TEXTAREA contents are used as the HTML source for the IFRAME.

fenway