JavaScript Window method: alert()
[this page | pdf | back links]
The alert() method (when applied to Window
objects in the JavaScript
BOM) displays text in
an alert box.
It
has the following syntax with the following parameters. It does not return
a value.
window.alert(message)
Parameter
|
Required / Optional
|
Description
|
message
|
Optional
|
String specifying text
to display in an alert box
|
EXAMPLE:
HTML USED IN THIS EXAMPLE:
<!DOCTYPE html>
<html> <!-- Copyright (c) Nematrian Limited 2018 -->
<head></head>
<body>
try clicking on this
<span style="background-color: yellow;" onclick="myOnclick()">element</span>
(it should create a window alert)<br>
<script>
function myOnclick() {window.alert("Hello");}
</script>
</body>
</html>
|
FUNCTION THAT MAY ASSIST IN TESTING WHETHER FEATURE IS SUPPORTED:
function isSupportedJavaScriptMethodWindowAlert() {
return !!window.alert;
} |
NAVIGATION LINKS
Contents | Prev | Next | JavaScript DOM (and BOM)