views:

144

answers:

1

Hello,

I am trying to use popupNode in a little javascript based firefox extension. So if a user right click on a link and then clicks on an additional menu item a new tab opens with the link (sorta like "open in new tab"):

` var foo = { onLoad: function() { // initialization code this.initialized = true; },

onMenuItemCommand: function() {

var tBrowser = document.getElementById("content");
var target = document.popupNode;

tBrowser.selectedTab = tab;
var tab = tBrowser.addTab(target);

} };

window.addEventListener("load", function(e) { foo.onLoad(e); }, false);

`

It works mostly, but I am wondering in that is the right use. The problem is I want replace some characters on the var target, but somehow that partdoes not work. something like target.replace() will cause problems. So I am guessing target is not a string.

Mostly I would like to know what popupNode actually does ...

thanks

Peter

A: 

I haven't really used "popupNode", but in general nodes aren't the same as strings. I suggest reading up on the Document Object Model (DOM) to learn more.

As far as replacing text, assuming popupNodes work like other nodes then something like this may work for you:

var target = document.popupNode;
target.innerHTML = target.innerHTML.replace("old_string", "new_string")
Tim Goodman
To add a little detail on nodes in general, basically an HTML page or XML document is structured like a tree, with one thing having children, and these child things having their own children, etc. These "things" are called nodes, and on a web page they could be HTML elements, comments, attributes, plain text, etc. If a node is, say, a div, you don't want to edit the div like a string, you want to edit the HTML contained *between* `<div>` and `</div>`, so you use the innerHTML property. Make sense?
Tim Goodman
As far as the meaning of popupNode in particular, I found this description that may be helpful:https://developer.mozilla.org/en/DOM/document.popupNode"When a popup attached via the popup or context attributes is opened, the XUL document's popupNode property is set to the node that was clicked on".So it's basically a way of getting a particular node of the document that then can presumably be modified in the same way as any other node.
Tim Goodman
Yep - I think this was it. thanks for your helpPeter
pmoosh
You're quite welcome
Tim Goodman
actually I found another hint, that recommends to use:gContextMenu.linkso I do:var target = gContextMenu.link; Firebug.Console.log(target.href); target.href = "bla" + target.href.replace(/#/g,"%23").replace(/=/g,"%3D").replace(/; Firebug.Console.log("gContextMenu.link - after:"); Firebug.Console.log(target.href); var tab = tBrowser.addTab(target);And it seems to well.
pmoosh