CSPP552: Web Programming, JavaScript part 14
Complicated Example
- To demonstrate JavaScript in a somewhat more complex program, I wrote
this program. See if you can tell what
it does before clicking on the link.
- If you try to look at the document source of this with Netscape, it may
not be what you expect! Use wget to snarf the document.
<html>
<head><title>JavaScript Rollover Annoyance</title>
<SCRIPT LANGUAGE="JavaScript">
<!-- Mouseover stuff
var Imageactive, Imageinactive;
if (document.images) {
Imageactive = new Image(100,100); Imageactive.src = "active.gif";
Imageinactive = new Image(100,100); Imageinactive.src = "inactive.png";
}
function image_on(img) {
if (document.images) document.images[img].src = Imageactive.src;
}
function image_off(img) {
if (document.images) document.images[img].src = Imageinactive.src;
}
// script ends here -->
</SCRIPT>
</head>
<body bgcolor="#ffffff">
Hi there. This is annoying and useless:<p>
<SCRIPT LANGUAGE="JavaScript">
<!-- duh..
for (i = 0; i < 6*15; i++) {
foo = "<a href=\"javascript:;\" onMouseOver=\"image_on('Image" + i +
"'); return true;\" onMouseOut=\"image_off('" + i +
"'); return true;\"\><img src=\"inactive.png\" name=\"Image" + i +
"\" border=0 width=100 height=100\></a\>";
document.writeln(foo);
if ((i+1)%6 == 0) document.writeln("<p\>");
}
// script ends here -->
</SCRIPT>
<p>
</body>
</html>
Next