views:

242

answers:

2

I can easily do execcommand on a contenteditable selection if using a button. However using any other element fails.

http://jsbin.com/atike/edit

Why is this and how can I make it work using a div element.

Thanks.

A: 

Most, if not all, of the WYSIWYG editors out there use an iframe element in order to not lose the selection. Another approach, although I haven't tried it, would be to store each selection made on that page after the mouseup event triggers.

Take a look at this page about Midas, Gecko's built-in rich text editor.

Ionuț G. Stan
Well it's definitely not all. Many editors, including google docs, do not use iframe. They must do it somehow.
Mark
Google docs is using an `iframe`. http://yfrog.com/0ngoogledocsp
Ionuț G. Stan
Ahh yes you're right.
Mark
I checked and realized one of the editors i was thinking of was just using buttons.
Mark
A: 

Google Wave doesn't use iFrames, it is purely contenteditable divs, however good luck searching through all their compressed code..

kaz