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

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>
LVL 1
James TalvyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

cwkhangCommented:
if(!navigator.javaEnabled())
{
      window.alert("Need a java enabled browser");
}
0
James TalvyAuthor Commented:
cwkhang.... Thats the whole point navigator.javaEnabled() is returning true on the computer that does not have Java installed.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

James TalvyAuthor Commented:
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
cwkhangCommented:
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
James TalvyAuthor Commented:
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
cwkhangCommented:
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
James TalvyAuthor Commented:
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
cwkhangCommented:
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
James TalvyAuthor Commented:
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
James TalvyAuthor Commented:
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
cwkhangCommented:
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
cwkhangCommented:
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
cwkhangCommented:
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
James TalvyAuthor Commented:
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
cwkhangCommented:
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
James TalvyAuthor Commented:
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
cwkhangCommented:
i found this
Web Administration: webadmin@ccs.neu.edu
from http://www.ccs.neu.edu/contact/index.html
0
James TalvyAuthor Commented:
I appreciate that but that must be the web master at that school.... Mr "lpok" is a student there.
0
cwkhangCommented:
icic so fast u got reply from them
how about this address: webservices@www.neu.edu
from http://www.northeastern.edu/
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Components

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.