ContentEditable / DesignMode in FireFox

After messing around with this for about 15 minutes in Camino and FireFox, it looks like Gecko requires you to use an iframe, then do something like this:
document.getElementById("edit").contentDocument.designMode="on";
Does anyone know of an easier way that I'm missing? I don't really want iframes scattered everywhere.

ContentEditable / DesignMode in FireFox
Posted Jul 23, 2005 — 10 comments below
Posted Jul 23, 2005 — 10 comments below
Joern — Jul 24, 05 309
Phil Glanville — Sep 05, 05 371
For example, if your editing involves selecting a drop-down or inputting a font name in a text box - in IE (and I'm guessing Safari) there is no support for having multiple (visible) active and de-active selections at the same time.
And so, the text (in your editing area) looses selection as and when the selected text box or drop-select gains focus or selection itself. (in IE you can remember the selection objects but this doesn't look so great and is unnerving for your user as it appears that the selection disappears even tho you can still use it as if it were there).
In FireFox, the selected text remains selected and the recently clicked control still works as expected, because the editing selection is in a separate frame that has it's own selection handling.
True, if you want to make certain area's quickly and freely editable on your site... not quite sure why you want to, but then this isn't very useful. If however you are using this as an extended textarea, for non-HTML users on a forum for example; or making a WYSIWYG editor - then the IFRAME method works very well, and also gives more allowances for when coding cross-browser as it keeps your editor separate from your GUI.
Hope that helps someone - took me a little while to work out the idiosyncrasies in the separate browsers where designMode was concerned, and above is one of them.. :)
Q u e s t i o n
---
I have no way of testing designMode in Safari so i was just wondering if anyone knows if it behaves in much the same way as Internet Explorer does (in the way it edits text and the javascript code used to control it).
I have successfully managed to tame IE's contentEditable behaviour (by use of events) so that it behaves more like a text editor (and that of FireFox's designMode - one example is that rather than creating paragraphs and divs on the pressing of enter it just drops to a newline) but just wandering if there are any large differences i should be watching out / ready for as i am having to extend my WYSIWYG editor to handle Apple Machines with OS X for a client.
Cheers.
Nathan Trevivian — Sep 26, 05 400
If anybody believes this to be different, and has the documentation to back it up, I would really really appreciate someone letting me know ;)
Until then, if you want your WYSIWYG editor to work on OS X, just install FireFox on your Mac. It works fine.
Nathan Trevivian — Sep 26, 05 401
The JS is opensource, I believe...hmmm...
Torgeir — Feb 07, 07 3542
I'm curious on this topic to.. i'm trying to add an iframe to the body-tag after the page has loaded and setting it's designMode to "on" (in firefox). Is this possible or does it need to be set for all iframes on onload?
Any suggestions?
Scott Stevenson — Feb 07, 07 3548
I haven't done anything with this stuff in ages so I'm not sure.
Rob Reid — Feb 14, 08 5488
Also I have a problem that the caret/cursor keeps disapearing in the iframe and I cannot seem to find any code to force it to appear and move it to the end of the content especially when I have to reload the iframe through code (e.g to get round IEs non relative URI issue) does anyone have a solution for this?
function MakeEditable()
{
var theIframe = document.getElementById("myeditor")
theIframe.contentWindow.document.body.contentEditable = true;
//in moz you cannot change desgin mode straight away so try and then retry
try{
theIframe.contentWindow.document.designMode = "on";
}catch(e){
setTimeout(MakeEditable,250);
return false;
}
return true;
}
Dave — Jun 28, 08 6108
Thanks
Scott Stevenson — Jun 28, 08 6111
I haven't looked at this stuff in ages. I have no idea.
Daniel Phillips — Jan 01, 09 6580
What i would find good is a setting to precise a tag for new lines, having 60 div tags sucks!