The Confirm method presents a dialog window showing a prompt, and allows the user to choose between OK and Cancel.
It then returns with a value of True of OK choosen, or False if Cancel choosen.
The confirm method is most often used to check with the user before going on. For example, before loading a specific page (maybe one containg large images or frames) you could ask the user if they wanted it and then take appropriate action (choose not to load images or go to a no-frame version).
Try the following program out.
<h1>Cats</h1>
<SCRIPT LANGUAGE="JavaScript">
<!-- Hide from other browsers
var animated_images= confirm("Load animated images");
if (animated_images)
{document.writeln('<IMG SRC="animated.gif">');}
else
{document.writeln('<IMG SRC="static.gif">');}
// Stop hiding from browsers -->
</SCRIPT>
Note: You can copy the images from the course disk, or just put in a text message instead, or use the full path to the images given below.
http://www.dcs.uwaterloo.ca/~anderson/JavaScript/animated.gifRun the program.