1
votes

I am developing a firefox addon and I have to access the bookmark panel (to see it go to View->Sidebar->Bookmarks) and add a menu item to its context menu and when the menu item is clicked, get the item it was clicked on.

Por example: You open the bookmark panel and right click on Most Visited item and click on my menu item, then I want to know that the Most Visited item was clicked.

I tried the following code but with no success:

var bookmarkMenu = document.getElementById('menu_bookmarksSidebar');
var observer = document.createElement('observes'); //Observe when the bookmark panel shows
observer.setAttribute('element','viewBookmarksSidebar');
observer.setAttribute('attribute','checked');
observer.addEventListener('broadcast',function(event){
console.log("Bookmark panel showing " + event.target);

var sidebarWindow = document.getElementById("sidebar").contentWindow;//Try to get the sidebar window
if(sidebarWindow == null){
console.log("NULL");
}
var bar = sidebarWindow.getElementById("placesContext");
if (bar == null){
console.log("NO Sidebar window");
 }


});
bookmarkMenu.appendChild(observer);

I know how to access the browser window but I am unable to access the sidebar window. According to bookmarkPanel.xul, the id of context menu of that panel is "placeContext" but I can't access it. How I can I access the right-clicked bookmark/element?

event.target always gives me [object xulElement], how can I see what element it is?

I tried this:

var sXML = new XMLSerializer().serializeToString(event.target);

But doesn't seem to work

Thanks

1
Can teh solution be based on using xul overlay? or you need to do it with js? - Kashif
Need to do with javascript; it's an addon. Thanks - swe87

1 Answers

-1
votes

I think changing

var bar = sidebarWindow.getElementById("placesContext");

to

var bar = sidebarWindow.document.getElementById("placesContext");

will make a difference :-)