Creating Popup Windows
Window objects provides several different methods that allow you to launch popup windows that you can interact with for alerts, prompts, and notifications. The popup windows are displayed, and the user needs to interact with the popup before continuing to access the web page.
There are three kinds of popup boxes that can be created:
- alert(msg)—Launches a popup window that displays an alert message and provides a button to close the popup.
- confirm(msg)—Launches a popup window that displays a confirmation and message provides an OK and a Cancel button, which both close the popup. If you click the OK button, the return value from confirm() is true; otherwise, it is false.
- prompt(msg)—Launches a popup window that displays the message, a text box for input, and an OK and Cancel button, which both close the popup. If you click the OK button, the return value from prompt() is the text typed into the text box; otherwise, it is false.
The code that follows illustrates these popup boxes, as shown in Figure 3.1.
01 <html> 02 <head> 03 <title>Python Phrasebook</title> 04 <meta charset="utf-8" /> 05 <script type="text/javascript" 06 src="../js/jquery-2.0.3.min.js"></script> 07 <script> 08 var response = prompt("What is the airspeed " + 09 "velocity of an unladen swallow:"); 10 var result = confirm("You Entered " + response + 11 "is that OK?"); 12 if(result){ alert("You may pass.") } 13 else {alert("None Shall Pass.")} 14 </script> 15 </head> 16 <body> 17 </body> 18 </html>
ch0301.html
Figure 3.1 Various popup boxes, with the results being passed from popup to popup using JavaScript.