...

View Full Version : document.layers causing errors in IE



Rap_Jones
05-09-2006, 11:44 AM
ct.pease.nhctc.edu/~bryanwhite/cis224/final/index.js

There's something in the document.layers block that is commented out at the bottom of the page that is causing problems in IE. I can't understand why, but the script won't run if I leave it in. This project is due tonight and I've been messing with this for days.

The error I'm getting in IE is document.layers.quote is null or not an object

I've tried document.index_surround.document.quote also since the Quote div exists in a div called index_surround and it still gives me the same error replacing quote for index_surround in the error message.

Here's the code for reference. Any help would be greatly appreciated. If it were up to me, I wouldn't even involve document.layers, but we need to be compatible.


else if (document.layers) {

function generate() {

// generating a random number
var preResult = Math.random() * (quoteList.length);
var result = Math.floor(preResult);

// takes the number generated above, cross references it with the array and inserts the quote into the quote div

var layerWrite = document.layers['quote']

layerwrite.open();
layerWrite.write(quoteList[result]);
layerwrite.close();

}
}

} // end generate
}

Kor
05-09-2006, 12:16 PM
of course will generate errors (in fact should generate nothing) as document.layers is a reference used only by the old Netscape 4.x browsers. Nor Mozilla or Opera or even Netscape 7+ will use it.

I guess you may safely remove all that else if(){} block, as noone uses Netscape 4.x anymore.

Rap_Jones
05-09-2006, 12:38 PM
of course will generate errors (in fact should generate nothing) as document.layers is a reference used only by the old Netscape 4.x browsers. Nor Mozilla or Opera or even Netscape 7+ will use it.

I guess you may safely remove all that else if(){} block, as noone uses Netscape 4.x anymore.
This is the unanimous reaction I'm getting at every forum I've posted this problem to. The dillemma is that my instructor is requiring the document.layers in our project guidelines. I'm hoping that I can argue the point of view that no one uses document.layers in order to avoid having points taken off, but I'm fairly certain that he's not going to go for it. If there is some way to make this work in current versions of IE, that would be beautiful, but I fear that I'm screwed.

Kor
05-09-2006, 01:02 PM
Here you are:
(you have made a mistake, you have set the number of the array's elements to 4, but you have in fact 7 elements. Better do not set it


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script type="text/javascript">
var quoteList=[];
quoteList[0] = "Alright, Frankenstein! I'm running this monkey farm and I wanna know what the **** you're doing with my time! <br /> - Capt. Rhodes, <em>Day of the Dead</em> (1985)";
quoteList[1] = "When there's no more room in hell, the dead will walk the earth. <br /> - Peter, <em>Dawn of the Dead</em> (1978)";
quoteList[2] = "You're the Duke of New York! A #1!<br /> - The President, <em>Escape From New York</em> (1981)";
quoteList[3] = "Even though I am no worse than a beast, don't I deserve to live?<br /> - Oh Daesu, <em>Oldboy</em> (2003)";
quoteList[4] = "Warriors, come out to play-ee-ay!<br /> - Luther, <em>The Warriors</em> (1979)";
quoteList[5] = "Terrific! A six demon bag! Sensational! What's in it, Egg?<br /> - Jack Burton, <em>Big Trouble In Little China</em> (1985)";
quoteList[6] = "Heineken! **** that ****! Pabst Blue Ribbon!<br /> - Frank Booth, <em>Blue Velvet</em> (1986)";
function generate(){
var myquote= quoteList[Math.floor(Math.random()*quoteList.length)];
if(document.getElementById){document.getElementById('quote').innerHTML=myquote}
else if(document.all&&!document.getElementById){document.all['quote'].innerHTML=myquote}
else if(document.layers){
document.layers['quote'].open();
document.layers['quote'].write(myquote);
document.layers['quote'].close();
}
}
onload=generate;
</script>
</head>
<body>
<p id="quote"></p>
</body>
</html>

Kor
05-09-2006, 01:07 PM
check again the code, I have made some correction meanwile

brothercake
05-09-2006, 06:20 PM
The dillemma is that my instructor is requiring the document.layers in our project guidelines. I'm hoping that I can argue the point of view that no one uses document.layers in order to avoid having points taken off, but I'm fairly certain that he's not going to go for it.
Well if I was in your position, and in a militant mood, I would make the point that not only are you not going to include document.layers (or document.all), but he must change his syllabus to bring it up to date. It's total crap that you're being forced to waste your time with this arcana; it's about as much use as learning Welsh.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum