Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2004-10-21
21
Medium Priority
?
553 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
Comment
Question by:James Talvy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 11
  • 9
21 Comments
 
LVL 6

Expert Comment

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

Author Comment

by:James Talvy
ID: 12389327
cwkhang.... Thats the whole point navigator.javaEnabled() is returning true on the computer that does not have Java installed.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:James Talvy
ID: 12396789
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
ID: 12397837
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
 
LVL 1

Author Comment

by:James Talvy
ID: 12398715
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
ID: 12401837
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
 
LVL 1

Author Comment

by:James Talvy
ID: 12404296
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
ID: 12404338
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
 
LVL 1

Author Comment

by:James Talvy
ID: 12404455
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
 
LVL 1

Author Comment

by:James Talvy
ID: 12404987
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
ID: 12407462
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
ID: 12407552
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
ID: 12407563
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
 
LVL 1

Author Comment

by:James Talvy
ID: 12410805
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
ID: 12411590
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
 
LVL 1

Author Comment

by:James Talvy
ID: 12411705
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
ID: 12412196
i found this
Web Administration: webadmin@ccs.neu.edu
from http://www.ccs.neu.edu/contact/index.html
0
 
LVL 1

Author Comment

by:James Talvy
ID: 12412261
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:
cwkhang earned 750 total points
ID: 12412393
icic so fast u got reply from them
how about this address: webservices@www.neu.edu
from http://www.northeastern.edu/
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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 code hide show and toggles. 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…

636 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