Solved

Detecting if any Java is currently installed (Microsoft or Sun)

Posted on 2004-10-21
538 Views
Last Modified: 2013-11-18
I found the following simple JavaScript to detect if Java is available in the browser and the problem is that I just tested it on a PC that is brand new with no Miscrosoft VM nor Sun Java Plugin and it still prints "The browser detects that Java is installed".

Does someone have a bit of JavaScript..... without talking to an Applet (the problem is that you have to know when the applet is loaded) that will detect if the user has Java?

Thanks
-James

<html>
<head>
<title>Java Test Page</title>
</head>
<body>
<br>
<SCRIPT LANGUAGE="JavaScript">
if (navigator.javaEnabled()) {
document.write("<B>The browser detects that Java is installed.</B>") ;
}
</SCRIPT>
<br>
</body>
</html>
0
Question by:James Talvy
    20 Comments
     
    LVL 6

    Expert Comment

    by:cwkhang
    if(!navigator.javaEnabled())
    {
          window.alert("Need a java enabled browser");
    }
    0
     

    Author Comment

    by:James Talvy
    cwkhang.... Thats the whole point navigator.javaEnabled() is returning true on the computer that does not have Java installed.
    0
     
    LVL 6

    Expert Comment

    by:cwkhang
    0
     

    Author Comment

    by:James Talvy
    Unfortunately you miss the point and none of those pages answers the question.

    navigator.javaEnabled()  does NOT work.

    I have a breand new machine with no Java and I use navigator.javaEnabled() and it returns TRUE in Internet Explorer
    0
     
    LVL 6

    Expert Comment

    by:cwkhang
    yup i understand your question
    but i think there is solution from here http://www.experts-exchange.com/Web/Q_20627895.html
    did u try the solution, i did.
    i tested with java, javascript enabled
    javascript enabled and java disabled

    <script language="javascript" type="text/javascript">
    <!--
    var i_java;
    var v_java;
    // -->
    </script>
    <script language="vbscript">
    <!--
    on error resume next
    i_java = IsObject(CreateObject("Java"))
    // -->
    </script>
    <script language="javascript" type="text/javascript">
    <!--
    if (navigator.mimeTypes && navigator.mimeTypes.length)
     if (typeof(navigator.mimeTypes['application/x-java-vm']) != "undefined")
       i_java = true;
    if (navigator.plugins) {
     for (var i=0; i < navigator.plugins.length; i++) {
       if (navigator.plugins[i].name.indexOf("Java Plug-in") >= 0) {
         i_java = true;
         v_java = navigator.plugins[i].description.substring(navigator.plugins[i].description.lastIndexOf("Plug-in ") + 8, navigator.plugins[i].description.lastIndexOf(" for"));
         break;
       }
     }
    }
    // -->
    </script>

    Java enabled -
    <script language="javascript" type="text/javascript"><!--
    (navigator.javaEnabled()) ? document.writeln("Java is enabled!") : document.writeln("Java is NOT enabled!");
    // --></script>

    Java supported -
    <script language="javascript" type="text/javascript"><!--
    if (i_java || navigator.javaEnabled()) {
     document.writeln("Yes");
     if (v_java) {
       document.writeln(" - version " + v_java);
     }
    } else {
     document.writeln("No or unable to detect...");
    }
    // --></script>
    0
     

    Author Comment

    by:James Talvy
    Look at the line:

    if (i_java || navigator.javaEnabled()) {
    ...
    }

    I already told you that navigator.javaEnabled() does NOT work and always returns true.  So this line of code can not possibly work either.
    0
     
    LVL 6

    Expert Comment

    by:cwkhang
    here is my explanation
    java and javascript is different thing
    first, i must say there is nothing wrong on ur code.

    u see the following code
    <SCRIPT LANGUAGE="JavaScript">
    if (navigator.javaEnabled()) {
    document.write("<B>JAVASCRIPT is ENABLED on your browser</B>") ;
    }
    </SCRIPT>
    <NOSCRIPT>JAVASCRIPT is DISABLED on your browser</NOSCRIPT>

    you are using JAVASCRIPT to test in the first place, if your browser can run javascript of course there is output
    oso means tat if you see "JAVASCRIPT is ENABLED on your browser" then your browser CAN run javascript

    but if tat javascript is DISABLED on browser setting, you wil get output within noscript tag
    oso means that if you see "JAVASCRIPT is DISABLED on your browser" then javascript is disabled in your browser setting.

    no JVM or sun JRE installed doesn't mean that your browser can't run basic javascript
    but without JVM or sun JRE, u can't run applet like in http://go.icq.com
    0
     

    Author Comment

    by:James Talvy
    cwkhang.... I appreciate all your comments you have cleared up one thing.... what people were saying would detect Java is not detecting Java but is detecting JAVASCRIPT.   I unfortunately must defer back to my original question.

    "Does someone have a bit of JavaScript..... without talking to an Applet (the problem is that you have to know when the applet is loaded) that will detect if the user has Java?"

    I need to know if the browser supports Java not Javascript.

    I will try your code from above...

    <script language="javascript" type="text/javascript">
    <!--
    var i_java;
    var v_java;
    // -->
    </script>
    <script language="vbscript">
    <!--
    on error resume next
    i_java = IsObject(CreateObject("Java"))
    // -->
    </script>
    <script language="javascript" type="text/javascript">
    <!--
    if (navigator.mimeTypes && navigator.mimeTypes.length)
     if (typeof(navigator.mimeTypes['application/x-java-vm']) != "undefined")
       i_java = true;
    if (navigator.plugins) {
     for (var i=0; i < navigator.plugins.length; i++) {
       if (navigator.plugins[i].name.indexOf("Java Plug-in") >= 0) {
         i_java = true;
         v_java = navigator.plugins[i].description.substring(navigator.plugins[i].description.lastIndexOf("Plug-in ") + 8, navigator.plugins[i].description.lastIndexOf(" for"));
         break;
       }
     }
    }
    // -->
    </script>

    if navigator.plugins contains "Java Plug-in" does that work for Microsoft VM and Sun VM?
    0
     
    LVL 6

    Expert Comment

    by:cwkhang
    yes basically can use navigator.javaEnabled() to detect javascript
    as for java try to write a simple method in applet
    if the browser can run the applet then it is java enabled.
    wil giv u the example on the nex mornin as now is ald 4am
    0
     

    Author Comment

    by:James Talvy
    Thanks.... I actually would like to detect without an applet.

    I am trying to automate a web page so that the first time a user comes there and it detects that he does not have Java at all it sends him to a webpage where he can download the Java Plugin.

    Right now I have a manual process in place that if the users can see the Java applet then tehy click one button and Javascript will talk to the applet and direct them to the page for the Java Plugin or a different page for the Microsoft VM.  You can see it at the following URL:
      http://sn.cantordata.com/g3/launch/

    I would like it so that if there is no Java in the browser then it immediately goes to a page to download the Java Plugin from Sun instead of them having to hit "No Logo"....

    Thanks
    -James
    0
     

    Author Comment

    by:James Talvy
    Additionally...... I ran the following web page:


    <HTML>
    <HEAD>
    <TITLE>Java Test</TITLE>
    </HEAD>
    <BODY>
    Testing for Java......<BR><BR>

    <SCRIPT LANGUAGE="JavaScript">
    if (navigator.javaEnabled())
    {
      document.write("<B>The browser detects that JavaScript is enabled.</B><BR><BR>") ;
    }

    if(navigator.plugins)
    {
      document.writeln("<B><U>These are " + navigator.plugins.length + " plugins that I found....</U></B><BR>") ;
      for(var i=0; i<navigator.plugins.length; i++)
      {
        document.writeln("<B>Plugin " + i + ": [" + navigator.plugins[i].name + "]</B><BR>") ;
      }
    }
    else
    {
      document.writeln("<B>navigator.plugins is null</B><BR>") ;
    }

    if(typeof(navigator.mimeTypes['application/x-java-vm']) != "undefined")
    {
      document.writeln("<B>I found the x-java-vm mime type</B><BR>") ;
    }
    else
    {
      document.writeln("<BR><B>I did not find the x-java-vm mime type</B><BR>") ;
    }
    </SCRIPT>
    </BODY>
    </HTML>



    and got:

    Testing for Java......

    The browser detects that JavaScript is enabled.

    These are 0 plugins that I found....

    I did not find the x-java-vm mime type
    0
     
    LVL 6

    Expert Comment

    by:cwkhang
    all the code above http://www.experts-exchange.com/Web/Q_20627895.html
    and the following http://www.ccs.neu.edu/home/lpok/1945/redirect.html are not my code..

    i've go through many examples/tutorials for hours, and i think this should b working to meet ur requirements
    i've tested using firefox bcos this browser allow u to enable/disable Javascript or Java

    first, download this class file http://www.ccs.neu.edu/home/lpok/1945/Detect.class and save in same folder with html below


    <HTML>
    <HEAD>
    <TITLE>Detecting JVM</TITLE>
    </HEAD>

    <BODY>

    <FONT SIZE="5" COLOR="#990000"><B>Checking System:</B></FONT><BR><HR WIDTH="100%"><BR>
    <FONT SIZE="2">Please wait...</FONT><BR><BR>
    <!-- if JAVASCRIPT is DISABLED you will see this part, you have to understand that auto redirect to download java plugin is not possible here, as javascript is DISABLED so document.location will NOT work -->                              
    <NOSCRIPT>  
          <FONT SIZE="2">
          Unable to detect Java.
          <UL>

          <LI>Please make sure you have the latest version of Java installed. Java is available for FREE at <a href=http://java.sun.com/j2se/1.5.0/download.jsp>java.sun.com</a></LI>      
          </UL>
          </FONT>
    </NOSCRIPT>

    <!-- if JAVASCRIPT is ENABLED then proceed -->
    <SCRIPT LANGUAGE="javascript">

    var javaEnabled = true;
    var undefine = typeof test;


    if (typeof navigator != undefine
                && typeof navigator.javaEnabled != undefine
                && !navigator.javaEnabled())
          javaEnabled = false;

    //if JAVASCRIPT is ENABLED, let's redirect to the desired page
    if (javaEnabled) {
          document.write("<APPLET CODE='Detect.class' WIDTH='1' HEIGHT='1'>");
          document.write("<PARAM NAME='goodUrl' VALUE='JAVAOK.html'>"); //if JAVA is enable then auto redirect to here
          document.write("<PARAM NAME='badUrl' VALUE='http://java.sun.com/j2se/1.5.0/download.jsp'>");
          document.write("<PARAM NAME='length' VALUE='2'>");
          document.write("<PARAM NAME='class0' VALUE='javax.swing.JApplet'>");
          document.write("<PARAM NAME='class1 VALUE='javax.swing.JComponent'>");
          document.write("</APPLET>");
    }
    //if JAVASCRIPT is ON but JAVA is OFF, then u wil come to here
    else {
          document.write("<FONT SIZE='2'>");
          document.write("JAVASCRIPT is ENABLED but JAVA is DISABLED!");
          document.write("<UL>");
          document.write("<LI>If you are sure you have Java enabled, <a href='"JAVAOK.html"'>click here</a> to continue.</LI>");
          document.write("</UL>");
          document.write("</FONT>");
    }
    //if you would like to redirect user to download JRE (for javascript is on but java is off), replace with this code //document.location = "http://java.sun.com/j2se/1.5.0/download.jsp";
    </SCRIPT>

    </BODY>
    </HTML>

    post back if you have question
    cheers
    0
     
    LVL 6

    Expert Comment

    by:cwkhang
    aiks..the above is not working bcos of minor error
    use this one instead

    <HTML>
    <HEAD>
    <TITLE>Detecting JVM</TITLE>
    </HEAD>

    <BODY>

    <FONT SIZE="5" COLOR="#990000"><B>Checking System:</B></FONT><BR><HR WIDTH="100%"><BR>
    <FONT SIZE="2">Please wait...</FONT><BR><BR>
    <!-- if JAVASCRIPT is DISABLED you will see this part, you have to understand that auto redirect to download java plugin is not possible here, as javascript is DISABLED so document.location will NOT work -->                              
    <NOSCRIPT>  
         <FONT SIZE="2">
         Unable to detect Java.
         <UL>

         <LI>Please make sure you have the latest version of Java installed. Java is available for FREE at <a href=http://java.sun.com/j2se/1.5.0/download.jsp>java.sun.com</a></LI>    
         </UL>
         </FONT>
    </NOSCRIPT>

    <!-- if JAVASCRIPT is ENABLED then proceed -->
    <SCRIPT LANGUAGE="javascript">

    var javaEnabled = true;
    var undefine = typeof test;


    if (typeof navigator != undefine
              && typeof navigator.javaEnabled != undefine
              && !navigator.javaEnabled())
         javaEnabled = false;

    //if JAVASCRIPT is ENABLED, let's redirect to the desired page
    if (javaEnabled) {
         document.write("<APPLET CODE='Detect.class' WIDTH='1' HEIGHT='1'>");
         document.write("<PARAM NAME='goodUrl' VALUE='JAVAOK.html'>"); //if JAVA is enable then auto redirect to here
         document.write("<PARAM NAME='badUrl' VALUE='http://java.sun.com/j2se/1.5.0/download.jsp'>");
         document.write("<PARAM NAME='length' VALUE='2'>");
         document.write("<PARAM NAME='class0' VALUE='javax.swing.JApplet'>");
         document.write("<PARAM NAME='class1 VALUE='javax.swing.JComponent'>");
         document.write("</APPLET>");
    }
    //if JAVASCRIPT is ON but JAVA is OFF, then u wil come to here
    else {
         document.write("<FONT SIZE='2'>");
         document.write("JAVASCRIPT is ENABLED but JAVA is DISABLED!");
         document.write("<UL>");
         document.write("<LI>If you are sure you have Java enabled, <a href='JAVAOK.html'>click here</a> to continue.</LI>");
         document.write("</UL>");
         document.write("</FONT>");
    }
    //if you would like to redirect user to download JRE (for javascript is on but java is off), replace with this code //document.location = "http://java.sun.com/j2se/1.5.0/download.jsp";
    </SCRIPT>

    </BODY>
    </HTML>
    0
     
    LVL 6

    Expert Comment

    by:cwkhang
    to make it clear, here are the output

    IF JAVASCRIPT is OFF (dun care if JAVA is ON or OFF)
    output:
     Unable to detect Java.

        * Please make sure you have the latest version of Java installed. Java is available for FREE at java.sun.com


    IF JAVASCRIPT IS ON AND JAVA IS ON
    no output but auto redirect to value in goodUrl

    IF JAVASCRIPT IS ON BUT JAVA IS OFF
    output:
    JAVASCRIPT is ENABLED but JAVA is DISABLED!

        * If you are sure you have Java enabled, click here to continue.
    0
     

    Author Comment

    by:James Talvy
    Can you give me the source to Detect.class?

    On my computer it did the redirect to JAVAOK.html

    I will test your code on the computer without Java next.
    0
     
    LVL 6

    Expert Comment

    by:cwkhang
    you mean source code? i don't have Detect.java bcos is not my code
    i just refer to http://www.ccs.neu.edu/home/lpok/1945/redirect.html
    and found out that Detect.class is located at http://www.ccs.neu.edu/home/lpok/1945/Detect.class
    0
     

    Author Comment

    by:James Talvy
    ok... thanks alot.   I appreciate all your help.

    I just tried to contact the owner of that page but he has no email on his site.
    0
     
    LVL 6

    Expert Comment

    by:cwkhang
    i found this
    Web Administration: webadmin@ccs.neu.edu
    from http://www.ccs.neu.edu/contact/index.html
    0
     

    Author Comment

    by:James Talvy
    I appreciate that but that must be the web master at that school.... Mr "lpok" is a student there.
    0
     
    LVL 6

    Accepted Solution

    by:
    icic so fast u got reply from them
    how about this address: webservices@www.neu.edu
    from http://www.northeastern.edu/
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
    In this article you will learn how to create a free basic website on Bitbucket, a git service provider. Polymer creates dynamic HTML components, which allow more flexibility than static HTML. This tutorial uses Ubuntu Linux but can also be done on W…
    The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

    884 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now