1. Home
  2. Computing & Technology
  3. JavaScript

Is Java Enabled?

clr gif
Join the Discussion

Questions? Comments?

Glossary

Javascript Java

You can use Javascript to test whether your visitor's browser has a Java plug-in installed and enabled. This allows you to use Javascript to write the HTML to load the Java object into the web page only when the browser supports Java. Where the browser doesn't support Java you can write something else in its place instead if you want to.

Here is an example of how you do it:

if (navigator.javaEnabled()) {
document.write('<p><b>Java is enabled.<\/b><\/p>');
} else {
document.write('<p><b>Java is not enabled.<\/b><\/p>');
}

The following paragraph is produced by the above script to show you how it works.

Of course you will replace the content of the document.write statements with your own code to provide what you want to include in the web page when the browser has Java enabled and what (if anything) you want to include if Java isn't supported. The first document.write statement will probably contain your <object> - </object> code that will attach your Java object into the page (or embed if you are using deprecated HTML codes). The second document.write will contain whatever you want to replace the Java code with if the browser doesn't support Java.

Explore JavaScript
About.com Special Features

The Best Web Trends of the Decade

A look back at the best innovations, ideas and technologies over the last 10 years, More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. JavaScript

©2009 About.com, a part of The New York Times Company.

All rights reserved.