How to wait for a Java applet to finish loading on Safari?

前端 未结 3 1243
温柔的废话
温柔的废话 2021-01-12 15:38

This doesn\'t work in Safari:






        
      
      
      
3条回答
  •  悲&欢浪女
    2021-01-12 15:58

    Here is a generic function I wrote to do just this:

    /* 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") {
            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);
            }
        }
    }
    

    Call it like this:

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

提交回复
热议问题