开发者

Focus behavior in Applet-Javascript interaction

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()");
    }
}


// JSObject.getWindow(this).eval("focusMe()");
frame.requestFocuse();

by change to these should word.


We should encourage Oracle to support applets in web browsers more. After all, they are trying to push JavaFX technology which is applet technology. As far as focus isses are concerned, this seems to be complex. What about getting the basics rigt? Please refer to Applet steals Focus as a start.


The real question is why are you using an applet? It's been a while since I've done Java, but unless you've stripped out a lot of code from your example, it looks like you're just doing a simple dialog box. If that is the case, this can done easily and cheaply through any number of JavaScript libraries like Dojo and jQuery for example.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜