Forum Moderators: open
Here is the function.
function show(thetext){
var tipobj=document.getElementById("tip");
tipobj.innerHTML = thetext;
tipobj.style.top = document.all? document.body.scrollTop + "px" : pageYOffset + "px";
tipobj.style.left = "0px";
tipobj.style.visibility = "visible";
}
It has worked fine until I put it on another client's site. The code then only loaded it in the top left (ie DISAPPEARS when scrolled down) in IE.
AFter 40 minutes of elimination, the only difference in the sites were Strict Doctype vs. Transitional.
Apparently the code only works in Transitional. Can someone enlighten me why?
So maybe something similar to:
var D = document;
var scrollParent = D.compatMode && D.compatMode!= "BackCompat"
? D.documentElement
: D.body.scrollTop;
tipobj.style.top = (D.all? scrollParent.scrollTop:pageYOffset) + "px";
-------------------------
Microsoft decided that if you choose a Strict DOCTYPE that you must obtain the values from document.documentElement while if you choose a Transitional DOCTYPE or have no DOCTYPE at all that you must use document.body. Why they couldn't just populate both sets of fields like the other browsers do is anyone's guess. Having made the decision to only populate one set of fields they chose something completely unrelated to test for in order to decide which fields to populate.
So what does this mean for our Javascript coding? Well, if you don't use DOCTYPEs or use a Transitional DOCTYPE then you don't need to worry about document.documentElement and can keep using document.body.