简体   繁体   English

Applet与Javascript交互中的焦点行为

[英]Focus behavior in Applet-Javascript interaction

I have a web page with an applet that opens a popup window and also makes Javascript calls. 我有一个带有applet的网页,可以打开一个弹出窗口并进行Javascript调用。 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. 当该Javascript调用导致对HTML输入的focus()调用时,这将导致浏览器窗口将自身推入applet窗口的前面。 But only on certain browsers, namely MSIE. 但是仅在某些浏览器上,即MSIE。 On Firefox the applet window remains on top. 在Firefox上,小程序窗口保持在顶部。 How can I keep that behavior consistent in MSIE? 如何在MSIE中保持一致的行为? Note that using the old Microsoft VM for Java also achieves the desired (applet window in front) result. 请注意,使用用于Java的旧Microsoft VM也可以达到预期的效果(前面的applet窗口)。

HTML code: HTML代码:

<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: Java代码:

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. 通过更改这些应词。

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. 自从我完成Java以来​​已经有一段时间了,但是除非您从示例中剥离了大量代码,否则看起来您只是在做一个简单的对话框。 If that is the case, this can done easily and cheaply through any number of JavaScript libraries like Dojo and jQuery for example. 如果是这种情况,可以通过任意数量的JavaScript库(例如DojojQuery)轻松,廉价地完成此操作。

We should encourage Oracle to support applets in web browsers more. 我们应该鼓励Oracle在Web浏览器中更多地支持applet。 After all, they are trying to push JavaFX technology which is applet technology. 毕竟,他们正在努力推动JavaFX技术,即applet技术。 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. 请以Applet抢断Focus为起点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM