Nick Russler
Nick Russler

Reputation: 4688

Display prompt with firefox addon sdk

Is it possible to display a blocking "yes no" confirm dialog to the user using chrome privileges?

Something like this:

enter image description here

Upvotes: 2

Views: 609

Answers (2)

Nick Russler
Nick Russler

Reputation: 4688

I found the nsIPromptService, which does exactly what i want:

var chrome = require('chrome');
var prompts = chrome.Cc["@mozilla.org/embedcomp/prompt-service;1"].getService(chrome.Ci.nsIPromptService);
var remove = prompts.confirm(null, 'title', 'message');

Upvotes: 1

Noitidart
Noitidart

Reputation: 37238

accept nicks answer but read this:

Here's another way to access nsIPromptService. And check that page for more alerts:

var {Cu, Ci} = require('chrome');
Cu.import('resource://gre/modules/Services.jsm');
var doit = Services.prompt.confirm(null, 'title', 'message');
if (doit) { 
//he clicked yes
}

instead of null you can pass in a window object like Services.wm.getMostRecentWindow(null) and it becomes modal on that window

benefit of this way is it uses services.jsm so you arent loading nsipromptservice you're just getting a pointer to it, which is preferred way

Upvotes: 3

Related Questions