简体   繁体   中英

using popupNode in a javascript firefox extension

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

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")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM