Using the confirm() Method

The confirm() method works similarly to alert(), but this box is used to give the user a choice between OK and Cancel. You can make it appear in pretty much the same way, with the only difference being that instead of using the alert() method, you use the confirm() method.

NOTE

The Cancel button needs more JavaScript behind it than you have covered so far to make it work. Fear not, though; it will be covered!

So again, following the same routine as for the alert() method, you begin by adding the confirm() method to the script block as follows:

 <html> <head> <title>A Simple Page</title> <script language="JavaScript"> <!-- Cloaking device on! confirm(); // Cloaking device off --> </script> </head> <body> </body> </html> ...

Get JavaScript™ 1.5 by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.