Introduced in Gecko 2.0
(Firefox 4 / Thunderbird 3.3 / SeaMonkey 2.1)Prior to Gecko 2.0 (Firefox 4 / Thunderbird 3.3 / SeaMonkey 2.1), prompts (that is, alerts and other modal prompts) were window modal. That is, when an alert occurred, it blocked the user interface on all tabs in the window until the user dismissed the prompt.
Window-modal alert. |
Gecko 2.0 introduces tab modal prompts, which only block the tab with which they're associated. Only the window.alert()
method gets this by default; you get this by default.
Tab-modal alert. |
Disabling tab-modal prompts
You can disable tab-modal prompts and get back window-modal prompts by setting the prompts.tab_modal.enabled
preference to false
.
Using tab-modal prompts from chrome code
Currently, nsIPrompt
defaults to using window-modal prompts. You can force a prompt to be tab-modal using code like this:
let prompt = Components.classes["@mozilla.org/prompter;1"] .getService(Components.interfaces.nsIPromptFactory). .getPrompt(theWindow, Components.interfaces.nsIPrompt); let bag = prompt.QueryInterface(Components.interfaces.nsIWritablePropertyBag2); bag.setPropertyAsBool("allowTabModal", true);
From then on, you can use the nsIPrompt
object, prompt
, as usual. For example:
var factory = Components.classes["@mozilla.org/prompter;1"] .getService(Components.interfaces.nsIPromptFactory); var prompt = factory.getPrompt(gBrowser.contentWindow, Components.interfaces.nsIPrompt); var bag = prompt.QueryInterface(Components.interfaces.nsIWritablePropertyBag2); bag.setPropertyAsBool("allowTabModal", true); var promptArgs = ["Devmo Alert", "OMG! An alert!"]; prompt.alert.apply(null, promptArgs);
nsIPrompt
will automatically fall back to window-modal prompts when necessary (such as in situations in which tab-modal prompts aren't supported, or for prompts displayed outside the context of a tab).