Reputation: 15
i cannot get current content page html. when i trying access from script in xul element. not current open url.
i use this code:
alert(document.getElementById("html"));
it will alert null value, document return XUL object, not Html object. I want parsing current content page, but i dont know how to do it.
var mainWindow = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIWebNavigation)
.QueryInterface(Components.interfaces.nsIDocShellTreeItem)
.rootTreeItem
.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIDOMWindow);
alert(mainWindow.getBrowser().selectedBrowser.contentWindow.location.href);
alert(mainWindow.getBrowser().selectedBrowser.contentWindow.document);
when i use this code, no alert shown.
Upvotes: 0
Views: 2205
Reputation: 360
simply use content
before document
, for example:
alert(content.document.getElementById("html"));
may be you want to achieve
this:
alert(content.document.getElementsByTagName("html")[0].innerHTML);
Upvotes: 1
Reputation: 25332
var win = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator)
.getMostRecentWindow("navigator:browser");
win.alert(win.getBrowser().selectedBrowser.contentWindow.location.href);
If you run this code from the window
context, you can just remove the first part and have:
alert(window.getBrowser().selectedBrowser.contentWindow.location.href);
Upvotes: 1