简体   繁体   English

如何在Firefox中使用javascript访问书签面板?

[英]How to access the bookmark panel using javascript in firefox?

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. 我正在开发一个firefox插件,我必须访问书签面板(要查看它,请转到“视图”->“侧边栏”->“书签”),并将菜单项添加到其上下文菜单中,当单击该菜单项时,将其点击。

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. 根据bookmarkPanel.xul,该面板的上下文菜单的ID为“ placeContext”,但我无法访问它。 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? event.target总是给我[object xulElement],如何查看它是什么元素?

I tried this: 我尝试了这个:

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

But doesn't seem to work 但似乎不起作用

Thanks 谢谢

I think changing 我认为改变

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

to

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

will make a difference :-) 将有所作为:-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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