Boole 2014

JavaScript Lesson 1: JavaScript Alerts

Once you have mastered HTML, adding some javascript can make your page more interactive. This should come with a warning too that some javascript features appear so much like spam or ads that they may be automatically blocked by your computer.

Step 1. Find a space on your desktop or in a folder of your choosing and Right-Click and select "New" and then select "Text Document"

Step 2. Give this text file a name you are happy with. For example you could name it "yourname_javascript_lesson1.txt" or whatever name you like.

Step 3. Open up this file and type the following code (modifying the displayed text as you see fit).


<!doctype html>
<html>
<head>
<title>JavaScript Alerts</title>
</head>
<body>
<h1>JavaScript Alerts Example</h1>
<script type="text/javascript">
alert("I am a JavaScript alert");
</script>
<p>If you did not see an alert pop-up window, you may have your pop-up or adblocker settings too high. Also notice that if you did have a the java alert show up, this text didn't appear until that java alert was closed. So you could have certain sections of your page not show up UNTIL you have your website visitor click to close the java window. </p>
</body>
</html>


Step 4. Go to the File Menu and select "Save As..."
Step 5. Save the file as an html file. For example you could call it "yourname_javascript_lesson1.html"
Step 6. Double click on your new .html file and your website should open in the default browser window!

Click here for an example of the page with that code.

Take home message:

To add a java alert, you need to add the following 3 lines to your existing page.

<script type="text/javascript">
alert("I am a JavaScript alert");
</script>