Java Reference
In-Depth Information
Save this as ch10 _ question1.html .
You have many ways to determine if the browser is an older version of Internet Explorer. Your
author chose to check if document.addEventListener() is undefined. IE9+ supports the method,
whereas IE8 and below do not.
exercise 2 Question
Example 15 exhibits some behavior inconsistencies between standards‐compliant browsers and old‐
IE. Remember that the event handlers execute in reverse order in old‐IE. Modify this example to use
the new isOldIE() method so that you can write specific code for old‐IE and standards‐compliant
browsers (hint: you will call the addListener() method four times).
exercise 2 Solution
<!DOCTYPE html>
<html lang="en">
<head>
<title>Chapter 10: Question 2</title>
</head>
<body>
<img id="img0" src="usa.gif" />
<div id="status"></div>
<script src="ch10_question1.js"></script>
<script>
var myImages = [
"usa.gif",
"canada.gif",
"jamaica.gif",
"mexico.gif"
];
function changeImg(e) {
var el = evt.getTarget(e);
var newImgNumber = Math.round(Math.random() * 3);
while (el.src.indexOf(myImages[newImgNumber]) != -1) {
newImgNumber = Math.round(Math.random() * 3);
}
el.src = myImages[newImgNumber];
}
function updateStatus(e) {
var el = evt.getTarget(e);
var status = document.getElementById("status");
status.innerHTML = "The image changed to " + el.src;
if (el.src.indexOf("mexico") > -1) {
evt.removeListener(el, "click", changeImg);
Search WWH ::




Custom Search