Applet-Javascript 交互中的焦点行为

发布于 2024-08-15 05:30:10 字数 1449 浏览 5 评论 0 原文

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

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

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

时常饿 2024-08-22 05:30:10
// JSObject.getWindow(this).eval("focusMe()");
frame.requestFocuse();

通过更改这些应该词。

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

by change to these should word.

北音执念 2024-08-22 05:30:10

我们应该鼓励 Oracle 在 Web 浏览器中更多地支持小程序。毕竟,他们正在努力推动JavaFX技术,也就是applet技术。就焦点问题而言,这似乎很复杂。打好基础怎么样?请参阅 Applet 窃取 Focus 作为开始。

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.

記憶穿過時間隧道 2024-08-22 05:30:10

真正的问题是你为什么使用小程序?自从我完成 Java 以来已经有一段时间了,但是除非您从示例中删除了大量代码,否则看起来您只是在做一个简单的对话框。 如果是这种情况,这可以通过任意数量的 JavaScript 库轻松且廉价地完成,例如 jQuery

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文