Learn how to a build a cloud-first strategyRegister Now


JAVASCRIPT: Display code based on java being enabled

Posted on 2007-10-02
Medium Priority
Last Modified: 2012-05-05

I have a page where I check to see if java is enabled using javascript:

<script language="JavaScript">
var Jcheck = navigator.javaEnabled();

I then use that condition to see if it is true or false:

if (Jcheck != "true")   {
                  var appName = "!--"
else                  { var appName = "applet"      


document.write("<" + appName + "" );
If it is true then I want to write out the code to display an applet.

I thought maybe I could comment out the first part of the applet code if JAVA is NOT enabled but this did not work. Is there a way to display the applet code if java is enabled but hide it and display a message if java isn't enabled?

Any assistance would be appreciated!


Here is a sample of the applet code:

<applet name="My applet"
      width=400 height=250>
      <param name=NFParamScript value='

Background   = (,BOX,1,"null",TILE,black);
LabelPos     = 0.7;
DwellLabel   = ("",black,"Courier",16,0);
DwellBox     = (white,SHADOW,3,null,TILE,black);
Slices       = (35,orange,"Oranges",black,"Arial",14,0,null,NONE,4,"null",TILE,black),(65,red,"Apples",black,"Arial",14,0,null,NONE,4,"null",TILE,black);
ActiveLabels = (),();
SlicePos     = 0.0,0.0;
Legend                = ("Legend",black,"Helvetica",10,0);
LegendAxis            = (BOTTOM,LEFT);
LegendLayout          = (VERTICAL,RIGHT,0,0,TOPLEFT,-1);
LegendBox             = (null,NONE,1,null,TILE,black);
Question by:baxleyb
LVL 17

Accepted Solution

mreuring earned 600 total points
ID: 20002846
I would simply place a div in your document with a default text:
<div id="myJavaContainer">
  <p>This website needs to use Java and JavaScript technology. One, or both, of these technologies has not been enabled on your system.</p>

<script type="text/javascript">
if (navigator.javaEnabled()) {
  var container = document.getElementById("myJavaContainer");
  if (container) container.innerHTML = "<applet name=\"My applet\"\n" +
"      code=bla\n" +
"      codebase=./classes\n" +
"      archive=bla.jar\n" +
"      width=400 height=250>\n" +
"      <param name=NFParamScript value='\n" +
"\n" +
"Background   = (,BOX,1,\"null\",TILE,black);\n" +
"LabelPos     = 0.7;\n" +
"DwellLabel   = (\"\",black,\"Courier\",16,0);\n" +
"DwellBox     = (white,SHADOW,3,null,TILE,black);\n" +
"Slices       = (35,orange,\"Oranges\",black,\"Arial\",14,0,null,NONE,4,\"null\",TILE,black),(65,red,\"Apples\",black,\"Arial\",14,0,null,NONE,4,\"null\",TILE,black);\n" +
"ActiveLabels = (),();\n" +
"SlicePos     = 0.0,0.0;\n" +
"Legend                = (\"Legend\",black,\"Helvetica\",10,0);\n" +
"LegendAxis            = (BOTTOM,LEFT);\n" +
"LegendLayout          = (VERTICAL,RIGHT,0,0,TOPLEFT,-1);\n" +
"LegendBox             = (null,NONE,1,null,TILE,black);\n" +
"'>\n" +

This would replace the default text with your applet when java is enabled.

Author Comment

ID: 20014707
Perfect. Thanks for a simple and effective solution.

Featured Post

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!

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-…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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)
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…
Suggested Courses

810 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