Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    May 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    document.layers causing errors in IE

    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.

    Code:
    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	
    }

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    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.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    New to the CF scene
    Join Date
    May 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Kor
    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.

  • #4
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    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
    Code:
    <!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>
    Last edited by Kor; 05-09-2006 at 01:06 PM.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #5
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    check again the code, I have made some correction meanwile
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #6
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Rap_Jones
    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.
    Last edited by brothercake; 05-09-2006 at 06:22 PM.
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •