Focus behavior in Applet-Javascript interaction

Posted by Dan on Stack Overflow See other posts from Stack Overflow or by Dan
Published on 2009-12-10T20:48:21Z Indexed on 2010/04/29 7:27 UTC
Read the original article Hit count: 314

I have a web page with an applet that opens a popup window and also makes Javascript calls. When that Javascript call results in a focus() call on an HTML input, that causes the browser window to push itself in front of the applet window. But only on certain browsers, namely MSIE. On Firefox the applet window remains on top. How can I keep that behavior consistent in MSIE? Note that using the old Microsoft VM for Java also achieves the desired (applet window in front) result.

HTML code:

<html>
    <head>
    	<script type="text/javascript">
    		function focusMe() {
    			document.getElementById('mytext').focus();
    		}
    	</script>
    </head>
    <body>
    	<applet id="myapplet" mayscript code="Popup.class" ></applet>
    	<form>
    		<input type="text" id="mytext">
    		<input type="button" onclick="document.getElementById('myapplet').showPopup()" value="click">
    	</form>	
    </body>
</html>

Java code:

public class Popup extends Applet {
    Frame frame;
    public void start() {
    	frame = new Frame("Test Frame");
    	frame.setLayout(new BorderLayout());
    	Button button = new Button("Push Me");
    	frame.add("Center", button);
    	button.addActionListener(new ActionListener(){
    		public void actionPerformed(ActionEvent e) {
    			frame.setVisible(false);
    		}
    	});
    	frame.pack();
    }
    public void showPopup() {
    	frame.setVisible(true);
    	JSObject.getWindow(this).eval("focusMe()");
    }
}

© Stack Overflow or respective owner

Related posts about java

Related posts about applet