Previous Example-|-Next Example-|-Return to Chapter Listing

Example 13.9
Is Java Enabled? Using navigator.javaEnabled

[This example works with Netscape Navigator 3 and 4. (Though not with all of the preview release of Navigator 4; in 4b3, for instance, navigator.javaEnabled() always returns true, regardless of the browser's actual condition.) It will not work in Internet Explorer 3.]

This page uses the navigator.javaEnabled() method to see if your browser is Java-enabled. If it is, you'll see the earlier Java example. If not, you'll see an alert box.

Welcome to Tickets Online!

Kludge Kowboys in Concert, only $50.00 per ticket.
Please enter number of tickets desired:


We have this in the HEAD: <SCRIPT LANGUAGE="JavaScript"> <!-- var sAddJava = "<FORM NAME='myform'><INPUT TYPE='text' SIZE='10' NAME='numTickets'><INPUT TYPE='button' VALUE='Click to Order' onclick='document.ticket.setTicketQuantity(document.myform.numTickets.value)'></FORM></td><td><APPLET NAME='ticket' CODE='ticket.class' WIDTH=300 HEIGHT=200 mayscript></APPLET>" function javaYes() { document.write(sAddJava) } function javaNo() { alert("Your browser doesn't have Java enabled, so you can't run the Java app associated with this page. Either you have a non-Java browser, or Java is disabled in your browser's properties.)") document.write("<b>[The form and Java applet go here in a Java-enabled browser.]</b>") } function message(msg1, msg2) { alert(msg1 + msg2) } // --> </SCRIPT> Then this form in the BODY: <table border="0" width="100%"> <tr> <td> Kludge Kowboys in Concert, only $50.00 per ticket.<BR> Please enter number of tickets desired: <script language="JAVASCRIPT"> <!-- if (navigator.javaEnabled()) { javaYes() } else javaNo() //--> </script> </td> </tr> </table>
Previous Example-|-Next Example-|-Return to Chapter Listing