If I try to execCommand("justifycenter"...
a paragraph on my page in Firefox, it doesn't work; it's giving me this crazy error:
uncaught exception: [Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIDOMNSHTMLDocument.execCommand]" nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame :: editor.php?id=new :: onclick :: line 1" data: no]
I already know the reason; it's because my body tag doesn't have contenteditable on, which is annoying because the other browsers don't require this.
Now, my problem is I don't want the entire page to be editable. I'm writing something of a WYSIWYG page builder, and it's too much of a compromise to stick the entire editor into an iframe. Does anyone know any other alternatives? This whole execCommand stuff is new to me, and enabling it for the body, but disabling it for everything else seem开发者_运维问答s like a really bad hack.
Something like:
function myExecCommand(aCommandName, aShowDefaultUI, aValueArgument) {
document.contentEditable = true;
document.execCommand(aCommandName, aShowDefaultUI, aValueArgument);
document.contentEditable = false;
}
Should work, also according to MDC you can set contentEditable on the element in question instead of the body and it should work.
Note: I do believe 3 parameters are mandatory in FireFox.
I recently came upon this as well and I do believe this is a bug in Firefox (https://bugzilla.mozilla.org/show_bug.cgi?id=442186). The workaround is included in the discussion that follows albeit a bit ugly.
精彩评论