开发者

using popupNode in a javascript firefox extension

开发者 https://www.devze.com 2022-12-18 08:14 出处:网络
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 \"o

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 rig开发者_开发问答ht 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")
0

精彩评论

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

关注公众号