Solving the infamous document.layers no properties error?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Crimefighter

    #1

    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.ba nnerLayer :
    document.layers .bannerL
    ayer.document.l ayers[0];



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

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

    //update in seconds
    var UPDATE_FREQUENC Y = 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.be tterbox.net/";
    arrLinks[1] = "http://phoenix.betterb ox.net";
    arrLinks[2] = "http://lotn.betterbox. net";
    arrLinks[3] = "http://kivekia.betterb ox.net";
    arrLinks[4] = "http://patterns.better box.net";

    //Initialize array of images
    var arrImages = new Array();
    arrImages[0] = "http://promisedland.be tterbox.net/pl.gif";
    arrImages[1] = "http://phoenix.betterb ox.net/images/banner.gif";
    arrImages[2] = "http://lotn.betterbox. net/cgi-bin/banner.cgi";
    arrImages[3] = "http://kivekia.betterb ox.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_BANNE R)
    {
    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.ba nnerLayer :
    document.layers .bannerL
    ayer.document.l ayers[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(banne rtext);
    doc.close();
    }
    }
    //-->

    </script>
    </head>

    <!-- BANNER STARTS -->

    <table border=0 cellspacing=0 cellpadding=0 align=center>
    <tr><td>
    <div id="bannerLayer ">
    <layer name="bannerLay er" visibility="sho w" 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("ba nner()", (UPDATE_FREQUEN CY * 1000));
    //-->
    </script>
  • kaeli

    #2
    Re: Solving the infamous document.layers no properties error?

    In article <52859108.04040 81252.18ccb1ba@ posting.google. com>,
    crimefighter@ty po.net enlightened us with...[color=blue]
    >
    > It errors out here with that document.layers has no properties error:
    > var layer = (document.all)? document.all.ba nnerLayer :
    > document.layers .bannerL
    > ayer.document.l ayers[0];
    >[/color]

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

    var layer = document.getEle mentById?docume nt.getElementBy Id
    ("bannerLayer") :document.all?d ocument.all
    ["bannerLaye r"]:document.layer s?document.laye rs["bannerLaye r"]: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.



    Comment

    • Crimefighter

      #3
      Re: Solving the infamous document.layers no properties error?

      "kaeli" <tiny_one@NOSPA M.comcast.net> wrote in message
      news:MPG.1ae061 aac68fca09989d6 a@nntp.lucent.c om...[color=blue]
      > In article <52859108.04040 81252.18ccb1ba@ posting.google. com>,
      > crimefighter@ty po.net enlightened us with...[color=green]
      > >
      > > It errors out here with that document.layers has no properties error:
      > > var layer = (document.all)? document.all.ba nnerLayer :
      > > document.layers .bannerL
      > > ayer.document.l ayers[0];
      > >[/color]
      >
      > Watch for word wrap...
      > Not tested; works in theory.
      >
      > var layer = document.getEle mentById?docume nt.getElementBy Id
      > ("bannerLayer") :document.all?d ocument.all
      > ["bannerLaye r"]:document.layer s?document.laye rs["bannerLaye r"]:null;
      >
      > if (layer == null)
      > {
      > alert("your browser can't run this script");
      > return;
      > }[/color]

      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(banne rtext);
      doc.close();

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


      Comment

      • kaeli

        #4
        Re: Solving the infamous document.layers no properties error?

        In article <LLFdc.52595$aB .20316@newssvr1 6.news.prodigy. com>,
        crimefighter@de adspam.com enlightened us with...[color=blue]
        >
        > 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(banne rtext);
        > doc.close();
        >
        > doc has the same no properties error, and calls resizeTo not a
        > function...bleh .
        >[/color]

        change this block to

        if(layer.innerH TML) // was if (document.all)
        layer.innerHTML = bannertext;
        else if (document.layer s)
        {
        layer.resizeTo( imgW,imgH);
        var doc = layer.document;
        doc.open();
        doc.write(banne rtext);
        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.



        Comment

        Working...