- Detecting Browser Plug-ins
- Around and Around with Loops
- Writing with Loops
- Using For/In Loops
- Using Do/While Loops
- Checking if Java Is Enabled
- Functions
- Using Multi-level Conditionals
- Working with Functions That Return Values
- Handling Errors
- Putting More than One Script on a Page
- Scrolling Status Bars
- Status Bar Messages
Checking if Java Is Enabled
Before you call on a Java applet to enhance your page, you should check to see if the user even has a Java-enabled browser. You could try to infer Java capability by the version of the browser, but it's not a reliable indicator because most browsers that can use Java also offer the option to turn it off. So you want to use code that asks the browser if Java is enabled (that means it is turned on). Script 3.6 shows you how to do it. As a side benefit, the script will also tell you if JavaScript is disabled.

Script 3.6 This script tells you whether the user has a Java-enabled browser.
To check if Java is enabled
- document.write("Java is ") As you can see, there's no time wasted here; you start by writing the beginning of a text string into the document window.
- if (!navigator.javaEnabled()) { This test statement uses the navigator.javaEnabled() method, which does what you expect: it asks the browser if Java is enabled. But here it is preceded by the ! operator, which means "not," so the statement asks "is Java not enabled?"
- document.write("not ") If the result of the test in step 2 is true (that is, Java is not enabled), then write the word "not " into the text string that is being built. Note the extra space after the word "not" which will ensure that the text string looks right.
-
document.write("enabled.")
Whether Java is enabled or not, we get to this point and finish the sentence, and write out the page, as shown in
Figure 3.10
.
Figure 3.10 This user's Java is hot and perking away.
-
<noscript> JavaScript is not enabled. </noscript>
This is just plain HTML, but it is worth noting, as it tells the user that JavaScript isn't enabled.