如何调用 Firefox 书签对话框?

发布于 2025-01-02 10:15:50 字数 357 浏览 1 评论 0原文

我在 MDN 上读过这篇文章:
https://developer.mozilla.org/en/Places_utilities_for_JavaScript#Bookmark_Dialog< br> 但仍然不知道如何调用像

showAddBookmarkUI()

这样的函数我尝试了 PlacesUtils.showAddBookmarkUI(),但它不起作用。

I've read this article on MDN:

https://developer.mozilla.org/en/Places_utilities_for_JavaScript#Bookmark_Dialog
But still has no clue how to call for function like

showAddBookmarkUI()

I tried PlacesUtils.showAddBookmarkUI(), but it didn't work.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

黑寡妇 2025-01-09 10:15:50

本文自 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 将来可能会再次更改。您可以查看如何使用它的示例

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 实现)。

This article is outdated as of Firefox 4. This functionality is now implemented in the PlacesUIUtils module, method showBookmarkDialog(). You would call it like this:

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);

This is an internal module so it isn't really documented and the API might change again in future. You can see an example of how it is being used in the source code. Btw, if what you actually want to open is the list of bookmarks rather than the "Add Bookmark" dialog then you do it like this:

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();
}

(code mostly copied from PlacesCommandHook implementation).

素食主义者 2025-01-09 10:15:50

对于 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);

For SDK developers (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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文