473,386 Members | 1,598 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Solving the infamous document.layers no properties error?

I'm not a javascript guy, but the use of this banner rotator script
has given me fits. I know a few causes of the problem thus far, one
being the layer tags aren't supported under Netscape 7.1 just the
entire 4.X series. Script works fine under IE. I've tried a few
things to get it working under Netscape, such as defining a style for
the bannerLayer with the style tag, and trying to define the style
under the div tag, I've tried the getElementById but that doesn't work
either or else I'm doing it wrong.

It errors out here with that document.layers has no properties error:
var layer = (document.all)? document.all.bannerLayer :
document.layers.bannerL
ayer.document.layers[0];

http://mudlist.betterbox.net/testing.html

<script language="JavaScript">
<!--
/************************************************** ***********************/
/* SCRIPT SETTINGS
*/
/************************************************** ***********************/

//Wheteher the banner displayed randomly
var RANDOM_BANNER = true;

//update in seconds
var UPDATE_FREQUENCY = 150;

//banner height in pixels
var imgH = "70";

//banner width in pixels
var imgW = "468";

//Links target
var target = "_top";

//Initialize the array of links
var arrLinks = new Array();
arrLinks[0] = "http://promisedland.betterbox.net/";
arrLinks[1] = "http://phoenix.betterbox.net";
arrLinks[2] = "http://lotn.betterbox.net";
arrLinks[3] = "http://kivekia.betterbox.net";
arrLinks[4] = "http://patterns.betterbox.net";

//Initialize array of images
var arrImages = new Array();
arrImages[0] = "http://promisedland.betterbox.net/pl.gif";
arrImages[1] = "http://phoenix.betterbox.net/images/banner.gif";
arrImages[2] = "http://lotn.betterbox.net/cgi-bin/banner.cgi";
arrImages[3] = "http://kivekia.betterbox.net/images/kdbanner.jpg";
arrImages[4] = "/images/pebanner.gif";

//Any comments attached to the displaye image
var arrComments = new Array();
arrComments[0] = "Promised Land MUD";
arrComments[1] = "Phoenix MUD";
arrComments[2] = "Legend of the Nobles";
arrComments[3] = "Kivekian Dawn";
arrComments[4] = "Patterns End";

/************************ DO NOT EDIT BELOW THIS LINE
************************/
var updateBanner;
var COUNTER = 0;
var last = 0;

function buildBanner()
{
var randomNum;
if(RANDOM_BANNER)
{
randomNum = Math.floor(Math.random() * arrLinks.length);
while(randomNum == last)
randomNum = Math.floor(Math.random() * arrLinks.length);
last = randomNum;
}

var layer = (document.all)? document.all.bannerLayer :
document.layers.bannerL
ayer.document.layers[0];

COUNTER = (RANDOM_BANNER)? randomNum : COUNTER;

var aLink = (arrLinks[COUNTER])? arrLinks[COUNTER] : "#";
var anImage = (arrImages[COUNTER])? arrImages[COUNTER] : "";
var aComment = (arrComments[COUNTER])? arrComments[COUNTER] : "";
var aTarget = (target)? target : "_top";

var bannertext;

if ( anImage.indexOf("cgi") != -1 ) {
bannertext = "<iframe name=\"frame\" src=\"" + anImage + "\"
width=" + img
W;
bannertext += " height=" + imgH + " frameborder=0
scrolling=\"no\"></i
frame>";
}
else {
bannertext = "<a href=\"" + aLink + "\" target=\"" +
aTarget + "\">";
bannertext += "<img src=\"" + anImage + "\" border=0 alt=\"" +
aComment +
"\">";
bannertext += "</a>";
}
if(document.all)
layer.innerHTML = bannertext;
else
{
layer.resizeTo(imgW,imgH);
var doc = layer.document;
doc.open();
doc.write(bannertext);
doc.close();
}
}
//-->

</script>
</head>

<!-- BANNER STARTS -->

<table border=0 cellspacing=0 cellpadding=0 align=center>
<tr><td>
<div id="bannerLayer">
<layer name="bannerLayer" visibility="show" width=&{imgW};
height=&{imgH}; >
</layer>
</div>
</td></tr></table>
<!-- BANNER ENDS -->

<!-- KEEP THIS SCRIPT AT THE VERY BOTTOM OF THE PAGE -->
<script>
<!--
function banner()
{
buildBanner();
COUNTER++;
COUNTER = (COUNTER == arrLinks.length)? 0 : COUNTER;
}
updateBanner = setInterval("banner()", (UPDATE_FREQUENCY * 1000));
//-->
</script>
Jul 23 '05 #1
3 3284
In article <52**************************@posting.google.com >,
cr**********@typo.net enlightened us with...

It errors out here with that document.layers has no properties error:
var layer = (document.all)? document.all.bannerLayer :
document.layers.bannerL
ayer.document.layers[0];


Watch for word wrap...
Not tested; works in theory.

var layer = document.getElementById?document.getElementById
("bannerLayer"):document.all?document.all
["bannerLayer"]:document.layers?document.layers["bannerLayer"]:null;

if (layer == null)
{
alert("your browser can't run this script");
return;
}

--
--
~kaeli~
The more ridiculous a belief system, the higher probability
of its success.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 23 '05 #2
"kaeli" <ti******@NOSPAM.comcast.net> wrote in message
news:MP************************@nntp.lucent.com...
In article <52**************************@posting.google.com >,
cr**********@typo.net enlightened us with...

It errors out here with that document.layers has no properties error:
var layer = (document.all)? document.all.bannerLayer :
document.layers.bannerL
ayer.document.layers[0];


Watch for word wrap...
Not tested; works in theory.

var layer = document.getElementById?document.getElementById
("bannerLayer"):document.all?document.all
["bannerLayer"]:document.layers?document.layers["bannerLayer"]:null;

if (layer == null)
{
alert("your browser can't run this script");
return;
}


Yes that fixed that problem, then it fires off more errors with this part:

layer.resizeTo(imgW,imgH);
var doc = layer.document;
doc.open();
doc.write(bannertext);
doc.close();

doc has the same no properties error, and calls resizeTo not a
function...bleh.
Jul 23 '05 #3
In article <LL******************@newssvr16.news.prodigy.com >,
cr**********@deadspam.com enlightened us with...

Yes that fixed that problem, then it fires off more errors with this part:

layer.resizeTo(imgW,imgH);
var doc = layer.document;
doc.open();
doc.write(bannertext);
doc.close();

doc has the same no properties error, and calls resizeTo not a
function...bleh.


change this block to

if(layer.innerHTML) // was if (document.all)
layer.innerHTML = bannertext;
else if (document.layers)
{
layer.resizeTo(imgW,imgH);
var doc = layer.document;
doc.open();
doc.write(bannertext);
doc.close();
}
else
{
// whatever you want to do for non-compliant browsers
}

--
--
~kaeli~
The Bermuda Triangle got tired of warm weather. It moved to
Finland. Now Santa Claus is missing.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: 2obvious | last post by:
This is a pipe dream, I realize, but I'm trying to emulate the functionality of the W3C DOM-supported document.getElementsByTagName method under the very nightmarish Netscape 4. Through some...
6
by: David List | last post by:
I'm having a problem using different properties of the document object in the example javascripts in my textbook with browsers that identify themselves as using the Mozilla engine. One example of...
3
by: Catherine Lynn Smith | last post by:
I am creating a webpage with dhtml <DIV> layers and I want a link on one layer to modify the content on another but I seem to keep running into errors. Basically I create a layer in the middle...
12
by: Kepler | last post by:
How do you get the height of the client browser in IE? Both document.body.clientHeight and document.body.offsetHeight return the height of the document. If the page is long and there's a vertical...
10
by: InvisibleMan | last post by:
Hi, Thanks for any help in advance... Okay, I have the JS listed below that calls for the display of the (DIV) tag... cookie function not included, as don't feel its necessary but you'll get the...
5
by: John | last post by:
Hi, I have the following code: <FORM> <font size="3">Brands </font><br /> <SELECT SIZE="1" NAME="categorylist" STYLE="font-size: 8pt"> <OPTION VALUE=http://my.domain,.com/cetegory1.html...
4
by: ashkaan57 | last post by:
Hi, I am using the following code to show/hide part of an html page. It works in Netscape and Firefox but dies in IE: "Error: document.layers is null or not an object" <style> ..noshow {...
7
by: Andrea | last post by:
Hi there - I'm hoping someone can help me; I've been struggling with this for a few days! :-) I have a webpage that is comprised of many forms containing questions. As the user answers one...
2
by: chrisg | last post by:
Hi I have a problem with the following javascript in firefox (works fine in IE). I've done some reading and found that i need to pass in the element ID, but i cant figure out how to do it. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.