我有一个网页,上面有一个小程序,可以打开一个弹出窗口,还可以进行Javascript调用。当该Javascript调用导致对HTML输入进行focus()调用时,会导致浏览器窗口将自身推到小程序窗口的前面。但仅限于某些浏览器,即MSIE。在Firefox上,小程序窗口保持在顶部。我如何在MSIE中保持这种行为的一致性?请注意,使用旧的Microsoft VM for Java也可以获得所需的(前面的小程序窗口)结果。
<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>
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()");
}
}