我讀過這篇文章MDN:
https://developer.mozilla.org/en/Places_utilities_for_JavaScript#Bookmark_Dialog
,但仍然有不知道如何呼喚功能像如何調用Firefox書籤對話框?
showAddBookmarkUI()
我試過PlacesUtils.showAddBookmarkUI()
,但沒有奏效。
我讀過這篇文章MDN:
https://developer.mozilla.org/en/Places_utilities_for_JavaScript#Bookmark_Dialog
,但仍然有不知道如何呼喚功能像如何調用Firefox書籤對話框?
showAddBookmarkUI()
我試過PlacesUtils.showAddBookmarkUI()
,但沒有奏效。
這篇文章是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複製)。
對於SDK開發者(谷歌凹凸):
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);
尼斯和明確的答覆,非常感謝。 – Huang 2012-02-06 10:34:39
也謝謝我。我也完成了代碼。 – 2015-05-06 19:31:22
@ R-U-Bn:這個問題不是關於附加SDK,因此代碼不使用任何SDK模塊。我必須回滾您的更改。 – 2015-05-07 00:01:04