【问题标题】:alert window in my firefox addon我的 Firefox 插件中的警报窗口
【发布时间】:2013-08-14 15:03:04
【问题描述】:

我对 Firefox 插件开发很陌生,所以如果它太愚蠢,请原谅。我只是在堆栈中找不到答案。

我尝试从我的插件启动警报窗口:

alert('This is an alert');

但是,它不会识别“警报”。我应该包含哪些组件(需要)?

谢谢!

【问题讨论】:

标签: firefox firefox-addon-sdk


【解决方案1】:

对于模态警报,正如问题所问,最好使用提示服务,而不是警报服务:

var prompts = Cc["@mozilla.org/embedcomp/prompt-service;1"].getService(Ci.nsIPromptService);
prompts.alert(null, "AlertTitle", "AlertMessage");

【讨论】:

  • 您可能需要(如果您还没有)在您的插件脚本中更早地使用 Cc 和 Ci 模块,使用: const {Cc, Ci} = require("chrome");
  • @lam Zesh 或使用 const {Services} = Cu.import('resource://gre/modules/Services.jsm', null); Services.prompt.alert(null, "AlertTitle", "AlertMessage");
【解决方案2】:

也许这对你有帮助?

https://developer.mozilla.org/en-US/docs/XUL/School_tutorial/User_Notifications_and_Alerts?redirectlocale=en-US&redirectslug=XUL_School%2FUser_Notifications_and_Alerts

由于链接偶尔会失效,我会为您节省一些滚动时间并发布可能最有用的代码:

let alertsService =
  Cc["@mozilla.org/alerts-service;1"].getService(Ci.nsIAlertsService);
let title = this._bundle.getString("xulschoolhello.greeting.title");
let message = this._bundle.getString("xulschoolhello.greeting.label");

alertsService.showAlertNotification(
  "chrome://xulschoolhello/skin/hello-notification.png",
  title, message, true, "", this, "XULSchool Hello Message");

【讨论】:

  • 该问题要求提供模式警报(如 window.alert),而 alerts-service 不提供此功能
猜你喜欢
  • 2019-05-15
  • 2014-08-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-11-11
  • 2019-11-22
相关资源
最近更新 更多