Change the contents of the Html page to "fly" in the Firefox extension.

When the user clicks a button on the Firefox toolbar, I need to change the content of the currently active html page. In the standard version, it looks like this:

function injectNewContent() {

 var pageHtml =
            [
                "<html>",
                "<head>",
                "</head>",
                "<frameset cols='270,*' frameborder='0'>",
                "<frame name='frameI' src='http://www.123.com/default.html'>",
                "<frame name='frameII' src='" + document.location + "'>",
                "<noframes>",
                "<body>", 
                "noframes",
                "</body>",
                "</noframes>",
                "</frameset>",
                "</html>"
            ];

 var fullPageHtml = "";

 for (var i in pageHtml)
 {
     fullPageHtml += pageHtml[i];
 }

 window.document.write(fullPageHtml);
}

What do I need to change in this code to get the same functionality?

 var windowMediator = Components.classes['@mozilla.org/appshell/window-mediator;1'].
                      getService(Components.interfaces.nsIWindowMediator);
 var recentWindow = windowMediator.getMostRecentWindow("navigator:browser");

 recentWindow. ???

Or maybe I'm something wrong?

Thanks for any help ...

+3
source share
1 answer

You do not need to look for a browser window, your button is already sitting on one. To access the content area of ​​the current tab, just use window.content. This should do what you want:

var doc = window.content.document;
doc.open("text/html", true);
doc.write(fullPageHtml);
doc.close();

Although personally, I would prefer to assign the HTML code doc.documentElement.innerHTML.

+2
source

All Articles