DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Mozilla: Getting Editor From An Iframe

08.21.2008
| 969 views |
  • submit to reddit
        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);