我在MDN上看过这篇文章:
https://developer.mozilla.org/en/Places_utilities_for_JavaScript#Bookmark_Dialog
但仍然不知道如何调用像
showAddBookmarkUI()
我尝试了PlacesUtils.showAddBookmarkUI()
,但它没有用。
答案 0 :(得分:5)
这篇文章是outdated as of Firefox 4。此功能现在在PlacesUIUtils
模块,方法showBookmarkDialog()
中实现。你会这样称呼它:
Components.utils.import("resource://gre/modules/Services.jsm");
var uri = Services.io.newURI("http://example.com/", null, null);
Components.utils.import("resource:///modules/PlacesUIUtils.jsm");
PlacesUIUtils.showBookmarkDialog({
action: "add",
type: "bookmark",
uri: uri,
title: "Example bookmark"
}, window);
这是一个内部模块,所以它没有真正记录,API将来可能会再次发生变化。您可以看到如何使用in the source code的示例。顺便说一句,如果你真正想要打开的是书签列表而不是"添加书签"对话然后你这样做:
Components.utils.import("resource://gre/modules/Services.jsm");
var organizer = Services.wm.getMostRecentWindow("Places:Organizer");
if (!organizer)
{
// No currently open places window, so open one with the specified mode.
openDialog("chrome://browser/content/places/places.xul",
"", "chrome,toolbar=yes,dialog=no,resizable", "AllBookmarks");
}
else
{
organizer.PlacesOrganizer.selectLeftPaneQuery("AllBookmarks");
organizer.focus();
}
(代码主要是从PlacesCommandHook
implementation复制而来)。
答案 1 :(得分:0)
对于SDK开发人员(google bump):
const utils = require('sdk/window/utils');
const window = utils.getMostRecentBrowserWindow();
let { Cu } = require('chrome');
Cu.import("resource:///modules/PlacesUIUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
//Adding bookmark
var uri = Services.io.newURI("http://example.com/", null, null);
PlacesUIUtils.showBookmarkDialog({
action: "add",
type: "bookmark",
title: "Predefined title",
uri: uri
}, window);
//Editing existing one
PlacesUIUtils.showBookmarkDialog({
action: "edit",
type: "bookmark",
itemId: 575
}, window);