Thanks. The bottom line is that all of these approaches work when I
type them into Extension Developer's Javascript Shell, but not when
they're coded in the extension itself. I suspect it's a timing issue,
so had a try at attaching a web progress listener and calling the code
to update the document contents in when state is STATE_STOP.
However, being relatively new to web progress listeners that aren't
used at overlay scope, I'm fairly certain I've done this wrong (nothing
appears in stdout even though I have dump() statements in
onStateChange()):
var listener = {
QueryInterface: function(aIID) {
if (aIID.equals(Components.interfaces.nsIWebProgressListener)
||
aIID.equals(Components.interfaces.nsISupportsWeakReference)
||
aIID.equals(Components.interfaces.nsISupports))
return this;
throw Components.results.NS_NOINTERFACE;
},
onStateChange: function(aProgress, aRequest, aFlag, aStatus) {
if (aFlag & Components.interfaces
.nsIWebProgressListener.STATE_STOP) {
dump("onStateChange: STATE_STOP\n");
var doc = aProgress.DOMWindow.document;
doc.removeChild(doc.getElementsByTagName("html")[0]);
var content = "<html
xmlns="http://www.w3.org/1999/xhtml"><body><p>hello,wurld</p></body></html>";
var dom = new DOMParser().parseFromString(content,
"text/xml");
doc.appendChild(dom.documentElement);
}
return 0;
},
onLocationChange: function() {return 0;},
onProgressChange: function() {return 0;},
onStatusChange: function() {return 0;},
onSecurityChange: function() {return 0;},
onLinkIconAvailable: function() {return 0;}
};
// Attach listener and open new window
var wm =
Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator);
var win = wm.getMostRecentWindow("navigator:browser");
win.gBrowser.addProgressListener(listener,
Components.interfaces.nsIWebProgress.NOTIFY_STATE_ALL);
win.open("about:blank");
--- Nickolay Ponomarev <[EMAIL PROTECTED]> wrote:
> Since you're parsing it as XML, you should let the parser know that
> your
> elements are HTML. This is done by specifying an appropriate (XHTML)
> namespace.
>
> Also if you go that route, you ought to be calling adoptNode before
> appending
> the parsed tree to the tab's document, see
> http://www.w3.org/DOM/faq.html#ownerdoc
>
> And, not selectedTab, but gBrowser.contentDocument.
>
> If you wish to print HTML code, it probably would make more sense to
> use
> document.open / document.write
>
> Nickolay
>
>
> Eric H. Jung wrote:
> > OK, so I have this to create a new, empty tab and then insert
> content:
> >
> > var wm = Components
> > .classes["@mozilla.org/appshell/window-mediator;1"]
> > .getService(Components.interfaces.nsIWindowMediator);
> >
> > var win = wm.getMostRecentWindow("navigator:browser");
> > win.gBrowser.selectedTab = win.gBrowser.addTab("about:blank");
> > var content = "<html><body><p>hello, wurld</p></body></html>";
> > var dom = new DOMParser().parseFromString(content, "text/xml");
> > win.gBrowser.selectedTab.appendChild(dom.documentElement);
> >
> > The string-to-DOM code works fine, but nothing appears in the new
> tab
> > after executing the appendChild() call. Should I call this on some
> > child or parent of win.gBrowser.selectedTab?
> >
> > Thank you again,
> > Eric Jung
> >
>
> _______________________________________________
> Project_owners mailing list
> [email protected]
> http://mozdev.org/mailman/listinfo/project_owners
>
__________________________________________
Yahoo! DSL Something to write home about.
Just $16.99/mo. or less.
dsl.yahoo.com
_______________________________________________
Project_owners mailing list
[email protected]
http://mozdev.org/mailman/listinfo/project_owners