JavaScript for Beginners: Intercepting Clicks

  1. What is JavaScript?
  2. JavaScript for Beginners
  3. An image gallery

JavaScript turns every web page into a collection of objects that you can modify and interact with. JavaScript turns everything that the visitor does into events that you can modify and intercept.

Go to http://www.hoboes.com/NetLife/Web_Scripting/Web_Scripting_Resources/ to download the resource zip archive and uncompress it. Open the file “1941.html” in your favorite text editor. There are several links on that page; some of the links are local (they go to hoboes.com) and some of them are not local (they go to Wikipedia and Amazon). We’re going to make the non-local ones open in a new window (or tab, depending on the visitor’s preferences).

Look in the HTML’s “head” area for a comment that says “put your scripts.js here”. Underneath that line, add this:

<script type="text/javascript" src="scripts.js"></script>

This line tells the browser to look for some scripts in the file “scripts.js”. We’re going to put our JavaScript code there. The syntax for the <script> tag is very similar to the syntax for the <img> tag.

The <script> tag can go anywhere in your document, but you’ll usually put it in the <head> area when you’re using it to include a file containing JavaScript. We’ll use it for other purposes later in this tutorial.

  1. What is JavaScript?
  2. JavaScript for Beginners
  3. An image gallery