Updated April 1, 2023
- Message box helps to show alert messages in various aspects like Danger for showing dangerous action or negative action, Success used to show positive action, Info is used to show action or change where as Warning used to show warning where user want to give attention.
So in this syntax window. Alert () method is used without window prefix.
Alert box is used to show sure information through pop up window to the user on their browser window. That alert message can be Danger, Success, Warning, Info each is having different meaning as per their importance. Danger value is used to show dangerous or negative action in popup box. Success can be used to show successful and positive action where as Warning value is used to show warning message where need attention of the user. And Info is used to show neutral information regarding change or action. One can create more than one alert message boxes on webpage using script for closing popup boxes using onclick attribute by considering <span> on each element.
window.prompt("text", "default text")
In the first example we are going to create simple Alert Box on button click , so when user click on button he or she able to see pop up message window and once done, by clicking on Ok button popup window get closed.
After Clicking on the button
In this Example we are going to create Alert Boxes, Those are like Success, Info, Warning, Danger as discussed earlier, Let’s see example for it:
Whenever running this code it will show output like:
So from above Alert boxes we can close those alert boxes by clicking Cross sign given as below:
In this example we are going to create Confirm Box.
In this example we are going to create Prompt Box.
- All those message boxes further divided into the three types like Alert box, Confirm Box and Prompt Box having value Ok and Cancel, So user can use any one among it as per their choice.