开发者

Mozilla - how to load a TAB with document previously acquired through gBrowser.contentDocument?

开发者 https://www.devze.com 2023-03-25 02:29 出处:网络
I\'m developing an easy Mozilla Firefox extension (FF 5.0 and above), and I need a manner in which I can get the content document from a tab, for example:

I'm developing an easy Mozilla Firefox extension (FF 5.0 and above), and I need a manner in which I can get the content document from a tab, for example:

<JavaScript function called from XUL document>
var content_1 = gBrowser.contentDocument;

and the goal is to put that content again in another tab, for example:

Application.activeWindow.activeTab.contentDocument = content_1;

but that's not working becasue content.document or contentDocument are read-only.

I mean, instead of getting the URL and reloading the page, I would like to the the tab's content itself and then assign it to another tab.

I'd also like to find a way to get the content of a tab including text filled in by a开发者_Go百科 user in HTML textboxes or wherever in the document, for example, a forum post text before sending it. I'm not sure this last thing is possible whithout having to read the memory or complicating too much the thing...


You cannot change contentDocument but you can change document contents. In particular, you can replace the document's root node. This should do:

var targetDoc = Application.activeWindow.activeTab.contentDocument;
var newRoot = targetDoc.importNode(content_1.documentElement, true);
targetDoc.replaceChild(newRoot, targetDoc.documentElement);

When I tried this copied document's contents including dynamic information like textbox input.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号