JavaScript – Popup Boxes

Basic Code:

<!DOCTYPE html>
<html>
<body>

<p>Click the button to display an alert box.</p>

<button onclick="myFunction()">Try it</button>

<script>
function myFunction()
{
alert("I am an alert box!");
}
</script>

</body>
</html>

Complete List:

// Alert Box - only alert
alert("Warning!"); 

// Confirm Box - OK or Cancel confirmation
window.confirm("Are you sure?");  

// Prompt Box - with Input field
window.prompt("Type your name","name...");

Special Characters you can use with Pop Boxes:

// Line Breaks (per andare a capo)
alert("Hello\nHow are you?"); // notice \n (ha l'effetto di <br>)

// Complete list
\'	single quote
\"	double quote
\\	backslash
\n	new line
\r	carriage return
\t	tab
\b	backspace
\f	form feed

My official WebSite >