本文介绍了使用firefox扩展程序以编程方式在书签工具栏中添加书签页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一个firefox扩展程序,该扩展程序将当前页面添加为书签,并在书签工具栏中添加一个条目.使用此处中找到的文档中的示例只能将链接添加为书签,而不能使其显示在书签工具栏中.我在文档中或Google上找不到与此相关的帮助.

I'm trying to make a firefox extension that bookmarks the current page and adds an entry in the bookmarks toolbar. Using the example in the documentation found here I was only able to only bookmark a link but not make it appear in the bookmarks toolbar. I was unable to find anything helpful in the documentation or on google related to this.

这是我的代码:

let { Bookmark, save } = require("sdk/places/bookmarks");

// Create a new bookmark instance, unsaved
let bookmark = Bookmark({ title: "Test", url: "http://mozilla.org" });

// Attempt to save the bookmark instance to the Bookmarks database
// and store the emitter
let emitter = save(bookmark);

这是完全不可能吗?还是我忽略了文档中的某些内容?

Is this simply not possible or is there something in the documentation that I've overlooked?

推荐答案

尝试将group设置为TOOLBAR,如下所示:

Try setting group to TOOLBAR, like so:

let { Bookmark, TOOLBAR, save } = require("sdk/places/bookmarks");

// Create a new bookmark instance, unsaved
let bookmark = Bookmark({
    title: "Test",
    url: "http://mozilla.org",
    group: TOOLBAR,
});

// Attempt to save the bookmark instance to the Bookmarks database
// and store the emitter
let emitter = save(bookmark);

有关这部分的更多信息在MDN上的页面

这篇关于使用firefox扩展程序以编程方式在书签工具栏中添加书签页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-10 04:32