The src attribute allows us to specify a file that will contain the JavaScript code we wish to use on that web page. The primary advantage of this is that we can reuse the same JavaScript code on multiple web pages. The following example shows this done.
<script src="jsCode.js"> </script>The above assume that a file with the name of jsCode.js exists in the same directory and this file contains the only JavaScript code and comments.
The JavaScript code in the file will be processed just as if that JavaScript code was in the HTML file between the opening and closing <script> tags.
For this lab, we will want to explore a few more parts of the document object in JavaScript. Check out http://www.w3schools.com/htmldom/dom_obj_document.asp for a discussion of more items.
The document.images[] returns a reference to all Image objects in the document. By using the length property we can determine the total number of images in a web page as follows:
imageCount = document.images.length;This assumes that imageCount is a variable.
The document.links[] returns a reference to all Link objects in the document. By using the length property we can determine the total number of links in a web page as follows:
imageCount = document.links.length;This assumes that imageCount is a variable.
For this lab assignment, complete the following:
This page contains 3 images.
Verify that your link and the file are viewable via a web browser from the URL of:
http://www.cs.uic.edu/~USERID where USERID is your CS account login name.You can check this out via the link to your home page on the CS 101 Student List page. Once you are at your home page, follow the link you added to your home page for this lab assignment.
To use the UNIX turnin command to electronically hand-in your html file using the project name of lab5. To submit the file in <filename> for lab5, the turnin command is entered as:
turnin -c cs101 -p lab5 <filename>To submit multiple files, list them after the name of the project. Thus if your HTML file has the name of lab5.html and your JavaScript file has the name of lab5.js, the command would be:
turnin -c cs101 -p lab5 lab5.html lab5.jsTo verify what you submitted using the turnin command type:
turnin -c cs101 -p lab5 -v