开发者

How do I dynamically add a div element to any page from a Firefox extension/Addon

I am writing an extension for firefox which will be used to annotate pages on the web via a service. I would like to have a div or an overlay element (probably XUL based) at the bottom of the page which will let people annotate a page and save it. Something like what the Google Friend Connect does on this page, but via an addon.

This floating div/overlay should show up for every page on FF and should render contents from a web service. How do I start building this out?

If it is possible to access DOM via a FF plugin and alter it, then I would like to be able to add a floating div to the body of t开发者_StackOverflow社区he document. But that doesn't work either. Example posted here: Dynamically adding a floating div to a page


There are several things you have to do:

  1. You probably want to add some custom CSS to style the div. You can use the stylesheet service.

  2. You have to attach an event handler to the load event ( or DOMContentLoaded), to be notified when a page finished loading. Have a look at Intercepting Page Loads and On page load.

  3. You need a reference to element you want the new element append to. Tabbed Browser provides some useful information. E.g. you can get a reference to the body of the current selected tab gBrowser.contentDocument.body.

Regarding your code example: You forgot the give the element the CSS property position: absolute; or position: fixed; (you have a typo in your code, you wrote postion), depending on whether it should appear at the bottom of the page or the screen.


You can do this (because I have). To do it you'll need to find the node you want to change the content of (if you're adding to the bottom of the page, you may want to use the <body> node I guess) and then call one of:

 insertBefore(theNewNode, afterThisNode);
 insertAfter(theNewNode, thisNode);

Or possibly, but I'm not sure:

 anExistingNode.innerHTML = anExistingNode.innerHTML + myNewContent;

That should be enough to get you started.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜