We help IT Professionals succeed at work.

JAVASCRIPT: Display code based on java being enabled

baxleyb
baxleyb asked
on
446 Views
Last Modified: 2012-05-05
Hi,

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

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

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

if (Jcheck != "true")   {
                  var appName = "!--"
                  document.write(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!

Thanks.

Here is a sample of the applet code:

<applet name="My applet"
      code=bla
      codebase=./classes
      archive=bla.jar
      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);
'>
</applet>
Comment
Watch Question

Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
Perfect. Thanks for a simple and effective solution.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.