By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,916 Members | 1,336 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,916 IT Pros & Developers. It's quick & easy.

Solving the infamous document.layers no properties error?

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
"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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.