Alert boxes are used to communicate messages to the user without taking them away from a web page. They are highly visible and must be acknowledged by clicking on ‘OK’ before the user can continue interacting with the web page.
Alert boxes can tell the user that they have not completed a form correctly, and confirmation boxes can be used to ask the user to confirm something eg. you could ask the user if they accept terms and conditions of your site. If they click on OK, they can continue using the site, but if they click on Cancel then they will be redirected to another page.
Alert boxes and confirmation boxes can be annoying for the user so they should only be used when absolutely necessary. Watch the video below which explains both alert and confirmation boxes, and then scroll down to see the sample code for each type.
Here is the code for alert boxes:
Here is the code for confirmation boxes: