Javascript 如何更改对话框窗口的“确定”/“取消”按钮的标签?

Javascript 如何更改对话框窗口的“确定”/“取消”按钮的标签?,javascript,firefox,xul,xpcom,Javascript,Firefox,Xul,Xpcom,如何更改XPCOM对话框窗口的OK/Cancel按钮的标签?您可以看到此类按钮的列表 事实上,我想要本地化ZoteroFirefox插件。显示此类对话框的部分代码如下所示: var regenerate = promptService.confirmEx( window, Zotero.getString('integration.revert.title'), Zotero.getString('integration.revert.body'), promp

如何更改XPCOM对话框窗口的
OK/Cancel
按钮的标签?您可以看到此类按钮的列表

事实上,我想要本地化ZoteroFirefox插件。显示此类对话框的部分代码如下所示:

var regenerate = promptService.confirmEx(
    window, 
    Zotero.getString('integration.revert.title'),
    Zotero.getString('integration.revert.body'),
    promptService.STD_OK_CANCEL_BUTTONS + promptService.BUTTON_POS_1_DEFAULT,
    null, null, null, null, out
);​

在支持每种浏览器的同时,要做到这一点,唯一的方法是使用对话框库创建它,这是它作为一个时尚库的生命末期,但仍然是真正的功能齐全。

在支持每种浏览器的同时,唯一的方法是使用对话框库创建它,这是它作为一个时尚库的生命末期,但是它仍然是功能齐全的。

首先,如果您想学习XUL,我强烈建议您使用,这是一个交互式工具,您可以使用它构建代码片段并预览您正在设计的内容

如果您以前从未使用过XUL,这将非常有用,因为它看起来很像HTML,但它的元素和方法不尽相同。它确实比HTML有点高,因为它用于构建桌面应用程序,可用于构建以下内容:

这些程序中的大多数都可以下载源代码并进行查看,就像查看文档列表一样。您还会注意到一些扩展,例如Firefox Web Developer插件。这是,这是。它恰好包括一个
对话框
目录和一个:

这看起来像:

所以你真的有很多选择,即使,如果你想


还有一种叫做。那里有很多,所以我相信你可以找到一些你想要做的事情。还有。首先,如果您想学习XUL,我强烈建议您使用,这是一个交互式工具,您可以使用它构建代码片段并预览您正在设计的内容

如果您以前从未使用过XUL,这将非常有用,因为它看起来很像HTML,但它的元素和方法不尽相同。它确实比HTML有点高,因为它用于构建桌面应用程序,可用于构建以下内容:

这些程序中的大多数都可以下载源代码并进行查看,就像查看文档列表一样。您还会注意到一些扩展,例如Firefox Web Developer插件。这是,这是。它恰好包括一个
对话框
目录和一个:

这看起来像:

所以你真的有很多选择,即使,如果你想


还有一种叫做。那里有很多,所以我相信你可以找到一些你想要做的事情。还有一个按钮。

如果需要自定义标签,则不应使用默认按钮:

promptService.confirmEx(
窗
getString('integration.revert.title'),
getString('integration.revert.body'),
promptService.BUTTON_POS_0*BUTTON_POS_0默认值,
getString('integration.revert.OK'),
getString('integration.revert.cancel'),
空,空,出
);​

这将第一个按钮声明为默认按钮,但不需要指定任何标志-已指定两个标签,因此将显示两个按钮。

如果需要自定义标签,则不应使用默认按钮:

promptService.confirmEx(
窗
getString('integration.revert.title'),
getString('integration.revert.body'),
promptService.BUTTON_POS_0*BUTTON_POS_0默认值,
getString('integration.revert.OK'),
getString('integration.revert.cancel'),
空,空,出
);​

这将第一个按钮声明为默认按钮,但不需要指定任何标志-已指定两个标签,因此将显示两个按钮。

@MihaiIorga在FireFox add-onshort摘要中列出以下答案:您不能。您可以使用自定义对话框窗口,但是(例如,使用jQuery和HTML创建)您不想使用吗?我想看一看,我认为它演示了您想在这里做什么。@mihaiorga在FireFox add-onshort摘要中给出了以下答案:您不能。您可以使用自定义对话框窗口,但是(例如,使用jQuery和HTML创建)您不想使用吗?我想看一下,我想这说明了您在这里想要做什么。谢谢,我不关心跨浏览器,我只想本地化Firefox插件。谢谢,我不关心跨浏览器,我只想本地化一个Firefox插件。谢谢,confirmEx有一个bug:,它还有其他选择吗?我该如何处理这个错误?@PHPst:是的,你可以创建自己的对话框。谢谢,confirmEx有一个错误:,它还有其他选择吗?我如何处理这个bug?@PHPst:是的,你可以创建自己的对话框。
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/"?>
<?xml-stylesheet href="chrome://web-developer/content/dialogs/style-sheets/message.css"?>
<!DOCTYPE dialog SYSTEM "chrome://web-developer/locale/dialogs/message.dtd">
<dialog buttons="accept" id="web-developer-message-dialog" onload="WebDeveloper.Message.initialize()" title="&webdeveloper.message.title;" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
    <script src="chrome://web-developer/content/common/common.js"/>
    <script src="chrome://web-developer/content/dialogs/javascript/message.js"/>

    <vbox id="web-developer-message-details">
        <description id="web-developer-message"/>
        <description id="web-developer-more-information" value="&webdeveloper.more.information;" onclick="WebDeveloper.Message.moreInformation()" class="url"/>
    </vbox>
</dialog>​
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<dialog id="myDialog" title="My Dialog"
        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
        onload="window.sizeToContent();"
        buttons="accept,cancel"
        buttonlabelaccept="Set Favorite"
        buttonaccesskeyaccept="S"
        ondialogaccept="return doSave();"
        buttonlabelcancel="Cancel"
        buttonaccesskeycancel="n"
        ondialogcancel="return doCancel();">
  <script>
  function doSave(){
      //doSomething()
      return true;
  }
  function doCancel(){
      return true;
  }
  </script>
  <dialogheader title="My dialog" description="Example dialog"/>
  <groupbox flex="1">
    <caption label="Select favorite fruit"/>
    <radiogroup>
      <radio id="1" label="Oranges because they are fruity"/>
      <radio id="2" selected="true" label="Strawberries because of color"/>
      <radio id="3" label="Bananna because it pre packaged"/>
    </radiogroup>
  </groupbox>
</dialog>
var prompts = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
                        .getService(Components.interfaces.nsIPromptService);

var check = {value: false};                  // default the checkbox to false

var flags = prompts.BUTTON_POS_0 * prompts.BUTTON_TITLE_SAVE +
            prompts.BUTTON_POS_1 * prompts.BUTTON_TITLE_IS_STRING  +
            prompts.BUTTON_POS_2 * prompts.BUTTON_TITLE_CANCEL;
// This value of flags will create 3 buttons. The first will be "Save", the
// second will be the value of aButtonTitle1, and the third will be "Cancel"

var button = prompts.confirmEx(null, "Title of this Dialog", "What do you want to do?",
                               flags, "", "Button 1", "", null, check);