View Full Version : Detecting if Java is installed
Gary Williams
12-05-2005, 12:38 PM
Hi All,
I need to be able to detect if Java is installed and, if yes, display an applet. If no, display a static gif instead.
Apart from buying "Browserhawk", I can't find a way of doing this. Anyone got a simple script for this?
Regards
Gary
BarrMan
12-05-2005, 12:47 PM
i don't know javascript but maybe you can run a javascript code with that returns a value and then check if the the value is 1 then run the program with the javascript because you'll know that it already ran a program and returned you the value you wanted.
I think.
_Aerospace_Eng_
12-05-2005, 02:02 PM
This is probably the best you can do.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<script type="text/javascript">
if(navigator.javaEnabled()){
document.write('Java is enabled');
}
else {
document.write('Java is not enabled');
}
</script>
</body>
</html>
I don't have java installed on Firefox for both security reasons and because it takes time to load on some applets.
Gary Williams
12-05-2005, 03:36 PM
Hi Aerospace,
Yup, that worked a treat! Now, the next trick is to run a java applet if java is enabled or display a static gif if java isn't enabled.
Tried the following (with and without the document.write) but it doesn't work. So how is a java applet called?
--------------------------
<script type="text/javascript">
if(navigator.javaEnabled()){
<APPLET CODE="test.class" CODEBASE="../html/" HEIGHT=153 WIDTH=240 ALT="">
<param name=reglink value="NO"> ; Optional URL link when the applet is "clicked"
etc
etc
</APPLET>
}
else {
document.write('Java is not enabled');
}
</script>
-------------------------
Regards
Gary
_Aerospace_Eng_
12-06-2005, 07:54 AM
Javascript and Java are not the same language so you can do something like this
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title></title>
</head>
<body>
<script type="text/javascript">
if(navigator.javaEnabled()){
document.write('<applet code="test.class" codebase="../html/" height="153" width="240">\n'+
'<param name="reglink" value="no">'+
'<param name="param1" value="value1">'+
'<param name="param2" value="value2">'+
'<param name="param3" value="value3">'+
'<param name="param4" value="value4">'+
'</applet>');
}
else {
document.write('Java is not enabled');
}
</script>
</body>
</html>
Gary Williams
12-06-2005, 06:09 PM
Hi Aerospace,
If I use:
<script type="text/javascript">
if(navigator.javaEnabled()){
document.write('Java is enabled');
}
else {
document.write('Java is not enabled');
}
</script>
then the correct message is displayed in IE, however if I use:
<script type="text/javascript">
if(navigator.javaEnabled()){
document.write('<applet code="test.class" codebase="../html/" height="153" width="240">\n'+
'<param name="param1" value="value1">'+
'</applet>');
}
else {
document.write('img src = ../picture.gif');
}
</script>
then I get both the applet and the picture directly beneath it! It seems to ignore the javascript test and just obey both document.write lines.
I shall keep trying.
Regards
Gary
_Aerospace_Eng_
12-07-2005, 09:13 AM
Can you post a link to your page? It shouldn't show the image unless java is disabled.
Gary Williams
12-07-2005, 11:22 AM
Hi Aerospace,
I got the second jpg image through a mistake in my programming. The behaviour this morning is this. A java enabled browser correctly displays the applet. A non java browser does not display the static jpg, just the outline of a 200 x 240 pix box with a small box top left with a red cross in it.
Using a link directly the static jpg displays it ok, ie, it's in the correct subdirectory.
The link to my test server is:
http://test.spectrumabacus.co.uk/html/checkagentlogin.asp
Regards
Gary
_Aerospace_Eng_
12-07-2005, 10:23 PM
It works fine for me.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<base href="http://test.spectrumabacus.co.uk/html/">
</head>
<body>
<script type="text/javascript">
<!--
if(navigator.javaEnabled()){
document.write('<APPLET CODE="ansnow.class" CODEBASE="../html/" HEIGHT="200" WIDTH="240" ALT="">\n'+
'<param name=credits value="Applet by Fabio Ciucci (www.anfyteam.com)">'+
'<param name=regcode value="NO">'+
'<param name=reglink value="NO">'+
'<param name=regnewframe value="YES">'+
'<param name=regframename value="_blank">'+
'<param name=statusmsg value="Snow">'+
'<param name=flakes1 value="500">'+
'<param name=flakes2 value="300">'+
'<param name=flakes3 value="100">'+
'<param name=flakes4 value="0">'+
'<param name=windmax value="1">'+
'<param name=windvariation value="7">'+
'<param name=speed value="4">'+
'<param name=backimage value="ansnow.jpg">'+
'<param name=bgcolor value="000133">'+
'<param name=overtext value="NO">'+
'<param name=overimg value="NO">'+
'<param name=overimgX value="0">'+
'<param name=overimgY value="0">'+
'<param name=memdelay value="1000">'+
'<param name=priority value="3">'+
'<param name=MinSYNC value="10">'+
'</APPLET>');
}
else {
document.write('<IMG HEIGHT=200 WIDTH=240 SRC="ansnow.jpg" BORDER=0 ALT="cabin" TITLE="cabin">');
}
//-->
</script>
</body>
</html>
Try the above example. Note I took the script directly from your page.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.