Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Mozilla: Getting Editor From An Iframe

DZone's Guide to

Mozilla: Getting Editor From An Iframe

·
Free Resource
Seems like getting an editor from a designMode/contenteditable iframe is harder than it should be in firefox:

First the docshell:

const Ci = Components.interfaces;
const Cc = Components.classes;

var editframe = window.frames[0];
var editdoc = editframe.document;

var docshell = editframe.QueryInterface(Ci.nsIInterfaceRequestor)
                        .getInterface(Ci.nsIWebNavigation)
                        .QueryInterface(Ci.nsIDocShell)


And now the editor (expanded)

var editor = editframe.QueryInterface(Ci.nsIInterfaceRequestor)
                      .getInterface(Ci.nsIWebNavigation)
                      .QueryInterface(Ci.nsIInterfaceRequestor)
                      .getInterface(Ci.nsIEditingSession)
                      .getEditorForWindow(editframe);

// -- OR --
var editor = docshell.QueryInterface(Ci.nsIInterfaceRequestor)
                     .getInterface(Ci.nsIEditingSession)
                     .getEditorForWindow(editframe);

// If you want:
editor.QueryInterface(Ci.nsIHTMLEditor);
Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}