2 Replies - 6388 Views - Last Post: 03 March 2008 - 07:03 PM

#1 sume  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 03-March 08

body onscroll doesn't fire in ie 6

Posted 03 March 2008 - 01:15 PM

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
SCRIPT LANGUAGE="Javascript" type="text/javascript">
function FloatPosition()
{
	
	var ns = (navigator.appName.indexOf("Netscape") != -1);
	var pos = document.getElementById("Spacer");
	var pad = ns ? pageYOffset : document.body.scrollTop;
	if(pad < 1) { pad =0; }
	pos.style.height = 200+ pad+'px';
}
</script>
<body class=<%=bodyClass%> onscroll="FloatPosition()" >


.....

</body>


The code above doesn't work with ie6, but works okay with firefox... what puzzled me was if i removed the dtd above it works (but the styles get messed up in the page and that's undesirable)

I'd really appreciate any help

Thanks

This post has been edited by sume: 03 March 2008 - 01:32 PM


Is This A Good Question/Topic? 0
  • +

Replies To: body onscroll doesn't fire in ie 6

#2 Nykc  Icon User is offline

  • Gentleman of Leisure
  • member icon

Reputation: 725
  • View blog
  • Posts: 8,638
  • Joined: 14-September 07

Re: body onscroll doesn't fire in ie 6

Posted 03 March 2008 - 01:16 PM

:code:
So it is easier to read please.
Was This Post Helpful? 0
  • +
  • -

#3 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1633
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: body onscroll doesn't fire in ie 6

Posted 03 March 2008 - 07:03 PM

One of your problems is IE doesnt recognize getElementById, so that Javascript will only work in browsers that support that. You could always do a DOM check to find out what the current browser supports, like


function DOMCall(name) 
{
  //Checks the DOM features available
   if (document.layers) //checks document.layers
        return document.layers[name];
   else if (document.all) //checks document.all
        return document.all[name];
   else if (document.getElementById) //checks getElementById
        return document.getElementById(name);
}




Then you would need to change your script like so:


function FloatPosition()
{
    
    var ns = (navigator.appName.indexOf("Netscape") != -1);
    var pos = DOMCall("Spacer");
    var pad = ns ? pageYOffset : document.body.scrollTop;
    if(pad < 1) { pad =0; }
    pos.style.height = 200+ pad+'px';
}


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1