Jump to content

clientHeight/clientWidth returning "Object Required" error


HaLo2FrEeEk

Recommended Posts

I'm pulling my hair out over this.  All I want to do is add snow to my website's homepage to complete the christmas theme, and I can't even do that.

 

From what I have read, clientHeight requires the strict doctype, which I can't use (I have to use transitional).  Is there an alternative to using clientHeight/Width that will work cross-browser and will not return an error everytime I load the page.  I'm sick of seeing that thing down there.  Here is the fulls cript I'm using:

 

  var no = 25; // snow number

  var dx, xp, yp;    // coordinate and position variables
  var am, stx, sty;  // amplitude and step variables
  var i;

  var doc_width = document.body.clientWidth;
  var doc_height = document.body.clientHeight;

  dx = new Array();
  xp = new Array();
  yp = new Array();
  am = new Array();
  stx = new Array();
  sty = new Array();

  var snow = new Array(2);
    snow[0]="http://infectionist.com/pages/seasonal_templates/christmas/images/snow.gif";
    snow[1]="http://infectionist.com/pages/seasonal_templates/christmas/images/snow2.gif";

  var flake = snow[Math.floor(Math.random()*2)];

  for (i = 0; i < no; ++ i) {
    dx[i] = 0;                        // set coordinate variables
    xp[i] = Math.random()*(doc_width-50);  // set position variables
    yp[i] = Math.random()*doc_height;
    am[i] = Math.random()*20;         // set amplitude variables
    stx[i] = 0.02 + Math.random()/10; // set step variables
    sty[i] = 0.7 + Math.random();     // set step variables
    if (i == 0) {
      document.write("<div id=\"dot"+ i +"\" style=\"POSITION: absolute; Z-INDEX: "+ i +"; VISIBILITY: visible; TOP: 15px; LEFT: 15px;\"><img src=\""+flake+"\" border=\"0\"></div>");
    } else {
      document.write("<div id=\"dot"+ i +"\" style=\"POSITION: absolute; Z-INDEX: "+ i +"; VISIBILITY: visible; TOP: 15px; LEFT: 15px;\"><img src=\""+flake+"\" border=\"0\"></div>");
    }
  }

  function snow() {
    for (i = 0; i < no; ++ i) {  // iterate for every dot
      yp[i] += sty[i];
      if (yp[i] > doc_height-50) {
        xp[i] = Math.random()*(doc_width-am[i]-30);
        yp[i] = 0;
        stx[i] = 0.02 + Math.random()/10;
        sty[i] = 0.7 + Math.random();
        doc_width = document.body.clientWidth;
        doc_height = document.body.clientHeight;
      }
      dx[i] += stx[i];
      document.getElementById("dot"+i).style.top = yp[i];
      document.getElementById("dot"+i).style.left = xp[i] + am[i]*Math.sin(dx[i]);
    }
    setTimeout("snow()", 10);
  }

  snow();

 

The error I get refers to line 8, character 3.  Here is that line with a padding of 5 lines:

 

var dx, xp, yp;    // coordinate and position variables
  var am, stx, sty;  // amplitude and step variables
  var i;

  var doc_width = document.body.clientWidth;
  var doc_height = document.body.clientHeight;

  dx = new Array();
  xp = new Array();
  yp = new Array();
  am = new Array();

 

Like I said, I'm going crazy here.  I can't stand it when something works for one person and not for me.  I got this off a website where it's running at and it works perfectly there, looks great.  I followed a link and saw it on Dynamicdrive.com, too, and it works like a charm there, so it's just me.

 

Can someone please, PLEASE help me solve this issue!  I would be very thankful, and I really want to have it snowing on my site to complete the holiday theme.

Link to comment
Share on other sites

Your problem is not that those parameters require a transitional doctype. They work just fine with a transistional doctype. This simple test works just fine in IE & FF:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<script>

function snow()
{
    alert(document.body.clientWidth);
    alert(document.body.clientHeight);
    return;
}

window.onload = snow;

</script>

</head>
<body>
Test
</body>
</html>

 

There must be something else wrong, but I'm unable to detemine from what you have provided so far.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.