如何让Firefox扩展中的模式对话框在屏幕上居中?

时间:2010-10-01 19:39:51

标签: firefox-addon modal-dialog

如果我有一个对话框,并且我想将它放在屏幕上,我可以做类似的事情:

var w = window.openDialog('chrome://syndicus/content/saveDialog.xul', '', 'chrome,dialog');
w.centerWindowOnScreen();

但如果它是模态对话框,则openDialog函数在用户按下某个内容之后才会返回,因此centerWindowOnScreen将不会被调用,直到它为止太晚了。如何将模态对话框居中?

2 个答案:

答案 0 :(得分:3)

尝试在功能中添加“centercreen”。

window.openDialog('chrome://syndicus/content/saveDialog.xul', '', 'chrome,dialog,centerscreen');

答案 1 :(得分:2)

将调用centerWindowOnScreen放入对话框本身的JavaScript中:

<dialog xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
        buttons="accept,cancel"
        ondialogaccept="onAccept();"
        ondialogcancel="onCancel();">
  <script type="text/javascript"><![CDATA[
    window.addEventListener('load', function() {
      window.centerWindowOnScreen();
    }, false);
    // more JavaScript ...
  ]]></script>
</dialog>