我在运行Windows CE 4.2 / 5.0的手持设备上使用了struts应用程序。
我们需要这个中另一个应用程序的功能,解决方案是弹出一个窗口到另一个应用程序(使用window.open()),运行该进程,然后关闭窗口以返回原始应用
通常,我们的应用始终专注于操作后的特定文本框。当新窗口关闭时,原始窗口不会成为活动窗口,我很难弄清楚如何激活窗口并专注于文本框。
有没有办法控制哪个窗口在关闭时变为活动状态并在必填字段上触发焦点事件?
提前感谢您的帮助。
编辑:如果有人遇到这个问题,结果是访问 window.opener 在Windows CE中不可用,除非OEM特别将其包含在他们的操作系统版本中。有关详细信息,请参阅this knowledgebase article。
答案 0 :(得分:1)
不确定Windows CE但使用JavaScript可以使用window.opener
从弹出窗口中引用父窗口。我写了一个小例子来证明。希望它对你有所帮助:
将其另存为parent.html
文件:
<html>
<head>
<script type="text/javascript">
function openPopup() {
window.open("child.html", "", "dependent=yes,directories=no,height=400px,width=600px,menubar=no,resizable=yes,scrollbars=yes,status=yes,title=yes,toolbar=no");
}
</script>
</head>
<body>
<input type="text" name="txt" id="txtId" value="blah" />
<input type="button" name="btn" value="Open popup" onclick="openPopup();" />
</body>
</html>
这是child.html
:
<html>
<head>
<script type="text/javascript">
function goToParent() {
window.opener.focus();
window.opener.document.getElementById("txtId").focus();
window.close();
}
</script>
</head>
<body>
Push the button to close this window and focus on the parent's textbox<br />
<input type="button" name="btn2" value="Close popup" onclick="goToParent();" />
</body>
</html>
您的弹出窗口应该关闭,并且应该通过调用页面获得焦点,即使它在后台或顶部还有其他窗口。