popUpDemo.html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>JavaScript Pop-Up Boxes</title> <style> body { font-family: Arial, sans-serif; text-align: center; margin-top: 50px; } button { padding: 10px 15px; font-size: 16px; margin: 10px; } </style> </head> <body> <h1>JavaScript Pop-Up Box Demonstration</h1> <button onclick="showAlert()">Show Alert</button> <button onclick="showConfirm()">Show Confirm</button> <button onclick="showPrompt()">Show Prompt</button> <script> function showAlert() { alert("This is an alert box!"); } function showConfirm() { const result = confirm("Do you want to proceed?"); if (result) { alert("You clicked OK!"); } else { alert("You clicked Cancel!"); } } function showPrompt() { const name = prompt("Please enter your name:"); if (name) { alert("Hello, " + name + "!"); } else { alert("No name entered."); } } </script> </body> </html>
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter