views:

33

answers:

1

Hello, I have a struts application being used on handheld devices running Windows CE 4.2/5.0.

We needed the functionality of another app in this one, and the solution was to pop up a window to the other app (using window.open()), run the process, and then close the window to return to the original app.

Normally our apps always focus on a specific textbox after an action. When the new window closes, the original window does not become the active window, and I'm having a hard time figuring out how to activate the window and focus on the textbox.

Is there a way to control which window becomes active when it closes and to trigger a focus event on the required field?

Thanks in advance for your help.

A: 

Not sure about Windows CE but with JavaScript you can use window.opener to refer to the parent window from within a popup. I wrote a little example to demonstrate. Hope it will be of help to you:

Save this as parent.html file:

<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>

and this as 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>

Your popup should close and focus should be gained by the calling page, even if it is in the background or there is some other windows on top.

dpb
Thanks, I'll give it a go.
IronicMuffin