模态对话框不与主HTA窗口通信

时间:2015-04-29 14:23:10

标签: javascript modal-dialog hta

我在HTA中有一个javascript,看起来像这样:

var result = null;
window.showModalDialog("dialog.hta", window, "dialogHeight:300px; dialogWidth:300px");
alert(result);

dialog.hta:

<html>
<head>
     <title>Dialog box</title>
     <meta http-equiv="MSThemeCompatible" content="yes"/>
</head>
<body style="background:#F0F0F0">
     <select id="colors">
          <option selected>Red</option>
          <option>Blue</option>
          <option>Green</option>
          <option>Yellow</option>
     </select><br/>
     <script type="text/javascript">
          function ok(){
               window.dialogArguments.result = colors.getElementsByTagName("option")[colors.selectedIndex].innerHTML;
               window.close();
          }
     </script>
     <button onclick="ok()">OK</button>
     <button onclick="window.close()">Cancel</button>
</body>
</html>

问题在于,当我按下OK时,主HTA窗口中的alert(result)始终显示为null,即使我单击模态对话框中的确定按钮也是如此。 如何在按下OK按钮时说明用户在列表中选择哪个选项,按下取消按钮时为null?

0 个答案:

没有答案