views:

505

answers:

2

Hi,

I have an ASP.NET page which loads a Java Applet. I am first checking that the client computer has the ability to run the applet (Java version etc) by giving the tag an ID of "AppletID" - then I call a function of this applet which always returns "true".

So, the following line of code: var isRunning = document.getElementById('AppletID').appletRunning() will return "true" if the method "appletRunning" in the applet is called successfully (indicating that the client can load the applet correctly).

This was always working until recently. However, lately, Firefox browsers give me an intermettent dialog box showing the "You do not have the required minimum version of Java..." message. (Other times it correctly detects that the applet can be loaded). The applet then proceeds to load correctly, but the dialog should not be shown in the first place. I wonder why this is happening - it possibly could be that document.getElementById('AppletID') is being null when it is checked, thus leading to the "catch" part of the "checkAppletRunning" method? IE is always OK and never returns this dialog box.

Below is the code of the .aspx page.

<script type="text/javascript" language="javascript">
    window.onload = function()
    {
        var appletCheck = checkAppletRunning();

        if (appletCheck == 1)
        {
            alert("Server is down...please try again later.");
            window.location.href = "Default.htm";
        }
        else if (appletCheck == 2)
        {
            alert("You do not have the required minimum version of Java enabled or installed. Java must be enabled or downloaded from http://www.java.com");
            window.location.href = "Default.htm";
        }
    }

    function checkAppletRunning()
    {
        var OK = 0;
        var serverDown = 1;
        var appletNotSupported = 2;

        try 
        {
            var isRunning = document.getElementById('AppletID').appletRunning();
            if (isRunning)
            {
                return OK;
            }
            else
            {
                return appletNotSupported;
            }
        } 
        catch (e)
        {
            return appletNotSupported;
        }
    }
</script>

I would appreciate any help in this matter,

Thanks in advance, Timothy

A: 

may be that the applet has not finished starting up.

try returning different result for an exception (or log the exception) to get a better idea why its failing.

objects
Hi, thanks for your reply. I've created another version of the page to print out the value of document.getElementById('AppletID') prior to "var isRunning = document.getElementById('AppletID').appletRunning();". I noticed that when Java is detected, the alert shows the instance of the entry class of the Applet. This alert is shown after the Java Dialog is dismissed by clicking "Run". However, when Java is not going to be detected, BEFORE the Java Dialog appears, the alert shows [object HTMLAppletElement]. So, I get the idea that Java has not yet started up? Any thoughts on this? Thanks!
Timothy Mifsud
one approach you can use is to instead have the java applet call the javascript. Would require a timer on the javascript side to tell it to stop waiting for the applet to call (ie. no java installed)
objects
A: 

A simpler approach is to rely on the fact that if Java is not available then the APPLET tag is not interpreted.

<HTML><HEAD></HEAD><BODY>
<APPLET CODE="MyApplet.class"
        NAME="myApplet"
        HEIGHT=400 WIDTH=400>

    <A HREF="nojava.html">Oups! You don't have JAVA enabled, click here.</A>

</APPLET>
</BODY></HTML>
RealHowTo