Alert boxes
This boxes alert users about something that you want them to know. The following example produces an alert box.
alert("Good Morning");
This will pop a window with the message "Good Morning". If you want to add several lines to the message you can separate each line with the \n (new line character).
Confirm boxes
Confirm boxes gives the user two options, and depending on what the user chose you can take an action. For example the code bellow ask the user if he/she want to continue to the site. If the answer is yes then an alert box shows "Welcome", if it's no then "Good Bye". Of course you can change those answers to whatever you want, for example you can redirect the user to a site depending on the answer.
<script> var conf=confirm("Do you want to continue to my site?") if (conf) alert("Welcome") else alert("Good Bye") </script> |
Prompt boxes
Prompt boxes are used to give the user the opportunity to enter some information. The bellow example asks the user for his/her name. The information given by the user is stored in the variable user. It can be used later for any purposes. In this example we made an alert box to welcome the user.
|
<script> var user=prompt("What is your name?") alert("Welcome "+user) </script> |