是否可以注册一个在java小程序完全加载时触发的javascript事件? [英] Is it possible to register a javascript event that triggers when java applet is fully loaded?

查看:19
本文介绍了是否可以注册一个在java小程序完全加载时触发的javascript事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Web 应用程序,它使用在 标签中定义的 java 小程序.是否可以添加小程序完全加载后触发的javascript事件?这是一些依赖于小程序完全加载和有效的初始化 javascript.

I have a web application that uses java applet defined in a <applet> tag. Is it possible to add a javascript event that is triggered after the applet is fully loaded? This is some initialization javascript that is dependent on that the applet is fully loaded and valid.

推荐答案

如果您没有对小程序的源代码控制,您可以在调用小程序的方法之前轮询要加载的小程序.这是我写的一个实用函数,它就是这样做的:

If you don't have source code control over the applet, you can poll for the applet to be loaded before calling methods on it. Here is a utility function I wrote that does just that:

/* Attempt to load the applet up to "X" times with a delay. If it succeeds, then execute the callback function. */
function WaitForAppletLoad(applet_id, attempts, delay, onSuccessCallback, onFailCallback) {
    //Test
    var to = typeof (document.getElementById(applet_id));
    if (to == 'function' || to == 'object') {
        onSuccessCallback(); //Go do it.
        return true;
    } else {
        if (attempts == 0) {
            onFailCallback();
            return false;
        } else {
            //Put it back in the hopper.
            setTimeout(function () {
                WaitForAppletLoad(applet_id, --attempts, delay, onSuccessCallback, onFailCallback);
            }, delay);
        }
    }
}

这样称呼它:

WaitForAppletLoad("fileapplet", 10, 2000, function () {
        BuildTree("c:/");
    }, function () {
        alert("Sorry, unable to load the local file browser.");
    });

这篇关于是否可以注册一个在java小程序完全加载时触发的javascript事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆