4

I've got an Java applet, which requires Java ver. at least 7.0.0.

Is there any possibility, to check whether an applet failed to load and display some message to user that he needs to update his Java software?

I've tried to use some background, but it shows only when there is no Java at all, otherwise it shows white rectangle with information of ClassNotFoundException. Here is sample of my HTML which includes my applet.

  <div style="background-image: url('img/appletbg.png'); width: 790px; height: 900px;">
        <applet code="MyPackage/MainClass.class" 
                       archive="applet/MyJar.jar" width="790" height="900">
        </applet>
  </div>

I know, that I can figure out installed Java version by JS, but it is client side, I'd prefer to show some message without ANY client interaction.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
filipbe
  • 165
  • 15
  • 1
    So you want to know the CLIENTS version without CLIENT interaction. I guess you can figure that its not possible – Hugo Delsing Feb 05 '13 at 14:07
  • 1
    This doesn't answer your question, but I find it helpful to just use Java 6. Many people don't have Java 7 and it's annoying to keep having to handle bug reports. – tckmn Feb 05 '13 at 14:07
  • Agree with @Doorknob. Is there any particular reason you are using Java 7? Are you using a particular feature (or features) unique to 7? – rmlan Feb 05 '13 at 14:14
  • 1
    *"but it is client side, I'd prefer to show some message without ANY client interaction."* What does 'client interaction' mean? JS will typically run without any prompt or action on the part of the end user. – Andrew Thompson Feb 05 '13 at 14:15
  • For OS X, I believe Apple is no longer updating Java 6 and therefore it has security flaws, the only updated version is Java 7, by Oracle themselves. Therefore, it makes sense to support Java 7. However, it should not be a requirement of the applet. – Chris Dennett Feb 05 '13 at 14:16
  • Added the [tag:javascript] tag on the basis that even though you "don't want it", it is the practical way to approach this entire problem. – Andrew Thompson Feb 05 '13 at 14:28

3 Answers3

1

Ok, I've figure out how to do this, using AndrewThompson suggestion, that using JS doesn't need any interacion.

Here is result to my code, figured out from this website: http://docs.oracle.com/javase/tutorial/deployment/deploymentInDepth/ensuringJRE.html

<script type="text/javascript" src="http://java.com/js/deployJava.js"></script>
<script type="text/javascript">
    if (deployJava.versionCheck("1.7.0_0+") == false) {                   
        userInput = confirm(
                "You need the latest Java(TM) Runtime Environment. " +
                "Would you like to update now?");        
        if (userInput == true) {  
            window.location = "http://java.com/en/download/testjava.jsp";
        }
    }
    else
    {
        // This are just the sample parameters for now!
        var attributes = {id:"applet", name:"TheApplet", code:"TheApplet"}; 
        var parameters = {jnlp_href: "http://localhost/TheApplet.jnlp"};

        deployJava.runApplet(attributes, parameters, "1.7.0_0");
    }
</script>
filipbe
  • 165
  • 15
0

Maybe it is not enought, but at the moment I think that you can use the alt attribute of the tag apple:

<applet code="MyPackage/MainClass.class" archive="applet/MyJar.jar" width="790" height="900" alt="alternative text">
</applet>

Reading a little bit more in the documentation, you have the onerror event that maybe you can use, but i have never used it.

NewRehtse
  • 338
  • 1
  • 5
  • 15
  • 1
    The `alt` attribute is only intended to be displayed when the user has Java installed but disabled. It has no effect when no JRE is installed, or when the JRE loads but finds fault in the applet. – Andrew Thompson Feb 05 '13 at 14:13
  • I spent all my life thinking that the alt attr works on errors! thanks! :) – NewRehtse Feb 05 '13 at 14:21
0

Try this :

    <SCRIPT LANGUAGE="JavaScript">
            error= errr;  
        function loadApplet() {
         if (!document.applets[0].isActive)

            alert(" Applet could not be loaded");
            }

        function errr() {
         alert("Applet could not be loaded");

         }
        }

add loadApplet method in body onload event

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
c.pramod
  • 606
  • 1
  • 8
  • 22
  • The `onload` event would typically be called as soon as the page elements are parsed by the browser. With the [new security environment](http://stackoverflow.com/q/14659057/418556) it is likely it will be fired prior to the user authorizing the dialog, or even figuring out what it is for. It would instead be necessary to do this check in a loop for certain time limit. – Andrew Thompson Feb 05 '13 at 14:26