如果我有一个对话框,并且我想将它放在屏幕上,我可以做类似的事情:
var w = window.openDialog('chrome://syndicus/content/saveDialog.xul', '', 'chrome,dialog');
w.centerWindowOnScreen();
但如果它是模态对话框,则openDialog
函数在用户按下某个内容之后才会返回,因此centerWindowOnScreen
将不会被调用,直到它为止太晚了。如何将模态对话框居中?
答案 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>